-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Description
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: stringThe 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 MEWhich 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"));Metadata
Metadata
Assignees
Labels
No labels