Skip to content

Is SpringDocSpecPropertiesConfiguration supported? #2993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
marceloverdijk opened this issue May 12, 2025 · 2 comments
Open

Is SpringDocSpecPropertiesConfiguration supported? #2993

marceloverdijk opened this issue May 12, 2025 · 2 comments

Comments

@marceloverdijk
Copy link

While going through the github source code I noticed the SpringDocSpecPropertiesConfiguration and SpecPropertiesCustomizer which state:

Allows externalizing strings in generated openapi schema via properties that follow conventional naming similar or identical to openapi schema

To set value of a string in schema, define an application property that matches the target node with springdoc.spec-properties prefix.

Sample supported properties for api-info customization:

springdoc.spec-properties.info.title - to set title of api-info
springdoc.spec-properties.info.description - to set description of api-info
springdoc.spec-properties.info.version - to set version of api-info

This seemed quite useful as I'm doing that now in a custom OpenApiCustomizer.

However the springdocs docs say nothing about this in https://springdoc.org/#properties

I gave it a try but unfortunately it was not working...

Debugging a bit, the SpringDocSpecPropertiesConfiguration itself is created as uncondionalClass but it's beans are never created.

@Lazy(false)
@Configuration(proxyBeanMethods = false)
@ConditionalOnBean(SpringDocConfiguration.class)
@Conditional(SpecPropertiesCondition.class)
public class SpringDocSpecPropertiesConfiguration {

The SpecPropertiesCondition seems to return false...

	@Override
	public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
		final BindResult<SpringDocConfigProperties> result = Binder.get(context.getEnvironment())
				.bind(SPRINGDOC_PREFIX, SpringDocConfigProperties.class);
		if (result.isBound()) {
			SpringDocConfigProperties springDocConfigProperties = result.get();
			if (springDocConfigProperties.getOpenApi() != null)
				return true;
			Set<GroupConfig> groupConfigs = springDocConfigProperties.getGroupConfigs();
			return groupConfigs.stream().anyMatch(config -> config.getOpenApi() != null);
		}
		return false;
	}

The springDocConfigProperties.getOpenApi() is null...
and as I have no groups also the later statement will not match.

Is this supposed to work, and if so how?

@marceloverdijk marceloverdijk changed the title Is SpringDocSpecPropertiesConfiguration supported Is SpringDocSpecPropertiesConfiguration supported? May 12, 2025
@marceloverdijk
Copy link
Author

Btw this (also undocumented) works...

springdoc.OpenApi.info.title=My API
springdoc.OpenApi.info.description=My Springdoc API
springdoc.OpenApi.info.version=1.0
springdoc.OpenApi.info.contact.name=Me
[email protected]
springdoc.OpenApi.info.contact.url=https://exmple.com

@marceloverdijk
Copy link
Author

But trying to add extensions:

springdoc.OpenApi.info.extensions[x-logo].url=https://avatars.githubusercontent.com?s=300
springdoc.OpenApi.info.extensions[x-logo].altText=My API Logo

won't work. Or at least is not in the rendered openapi spec.

However while debugging, it is in the SpringDocConfigProperties

Image

generated openapi spec (missing the x-logo extension):

{
  "openapi": "3.0.1",
  "info": {
    "title": "My API",
    "description": "My Springdoc API",
    "contact": {
      "name": "Me",
      "url": "https://example.com/",
      "email": "[email protected]"
    },
    "version": "1.0"
  },
  "servers": [
    {
      "url": "http://localhost:8080/",
      "description": "Generated server url".
    }
  ],
..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant