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

Serialisation: extensions in maps like paths are not written #2926

Closed
jmini opened this issue Aug 24, 2018 · 1 comment
Closed

Serialisation: extensions in maps like paths are not written #2926

jmini opened this issue Aug 24, 2018 · 1 comment

Comments

@jmini
Copy link

jmini commented Aug 24, 2018

When I run this code:

OpenAPI openAPI = new OpenAPI();

final Info info = new Info();
info.setDescription("API under test");
info.setVersion("1.0.7");
info.setTitle("My title");
openAPI.setInfo(info);
openAPI.servers(Collections.singletonList(new Server().url("http://localhost:9999/api")));

openAPI.path("/foo/bar",
        new PathItem().get(new Operation().responses(new ApiResponses().addApiResponse("200",
                new ApiResponse().description("it works!").content(
                        new Content().addMediaType("application/json", new MediaType().schema(new ObjectSchema()
                                .title("inline_response_200").addProperties("name", new StringSchema()))))))));
openAPI.getPaths().addExtension("x-test", "TEST ME"); // <= IMPORTANT LINE

String string = Yaml.mapper().writerWithDefaultPrettyPrinter().writeValueAsString(openAPI);
System.out.println(string);

I get this output:

openapi: 3.0.1
info:
  title: My title
  description: API under test
  version: 1.0.7
servers:
- url: http://localhost:9999/api
paths:
  /foo/bar:
    get:
      responses:
        200:
          description: it works!
          content:
            application/json:
              schema:
                title: inline_response_200
                type: object
                properties:
                  name:
                    type: string

The line for the extension x-test: TEST ME under paths: is missing.

I think that other maps with extensions might be concerned as well.


Expected output:

openapi: 3.0.1
info:
  title: Test extensions
  description: API under test
  version: 1.0.7
paths:
  /foo/bar:
    get:
      responses:
        200:
          description: it works!
          content:
            application/json:
              schema:
                title: inline_response_200
                type: object
                properties:
                  name:
                    type: string
  x-test: TEST ME

Which is correctly parsed by Swagger-Parser:

OpenAPIParser openApiParser = new OpenAPIParser();
OpenAPI openAPI = openApiParser.readLocation(inputSpec, null, new ParseOptions()).getOpenAPI();

System.out.println(openAPI.getPaths().getExtensions().get("x-test"));
frantuma added a commit that referenced this issue Aug 27, 2018
ref #2926 - fix extensions (de)serialization
@frantuma
Copy link
Member

Thanks for reporting this! fixed in #2931

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