Skip to content
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

Null vendor extensions are excluded from Json/Yaml #1525

Closed
loomisdf opened this issue Feb 25, 2022 · 1 comment
Closed

Null vendor extensions are excluded from Json/Yaml #1525

loomisdf opened this issue Feb 25, 2022 · 1 comment

Comments

@loomisdf
Copy link

Description

I haven't been able to create a vendor extension with a null value, the generated yaml/json won't include any. This could be a bug, but maybe there's a workaround I haven't found yet.

Versions

  • springboot 2.6.4
  • springdocs-openapi 1.6.6
  • Java 11

Example Code

@Configuration
public class SwaggerConfig {

    @Bean
    public OpenAPI api() {
        return new OpenAPI()
                .extensions(apiExtensions());
    }

    private Map<String, Object> apiExtensions() {
        var extensions = new HashMap<String, Object>();

        var linkedMap = new LinkedHashMap<String, String>();
        linkedMap.put("property1", "value1");
        linkedMap.put("property2", null);

        extensions.put("x-my-vendor-extensions", linkedMap);

        return extensions;
    }
}

Expected Output

"x-my-vendor-extensions": {
	"property1": "value1",
        "property2": null
}

Actual Output

"x-my-vendor-extensions": {
	"property1": "value1"
}

Null is an acceptable value for vendor extensions according to the openAPI spec: https://swagger.io/docs/specification/openapi-extensions/

The extension value can be a primitive, an array, an object or null

@bnasslahsen
Copy link
Collaborator

bnasslahsen commented Feb 28, 2022

@loomisdf,

This should completely be fixed at the source in the swagger-core library. Please raise an issue for it.
The OpenApiMixin should include NULL Values: @JsonInclude(value = Include.ALWAYS)

I have only added a workaround:
Use springdoc.writer-with-order-by-keys=true for the next release.

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

2 participants