swagger-core
swagger-core copied to clipboard
BUG Null-typed extensions elements disappear when creating yaml
When save openapi to yaml ( ObjectMapperFactory.createYaml(true).writeValueAsString(openApi) )
- some fields (with null type) in extensions disappear
- in licence section "extensions" word appear, but it shouldn't be there
As far I understand, parsing works correctly with extensions, but creating yaml works with bugs
Full code to reproduce:
import io.swagger.parser.OpenAPIParser;
import io.swagger.v3.core.util.ObjectMapperFactory;
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
OpenAPIParser parser = new OpenAPIParser();
var result = parser.readContents("""
openapi: 3.1.0
info:
title: Sample Pet Store App
contact:
name: API Support
url: https://www.example.com/support
email: [email protected]
x-myext:
key1: 1
key2: null
license:
name: asassaas
x-licence:
key1: 1
key2: null
version: 1.0.1
summary: A pet store manager.
x-info:
key1: 1
key2: null
""", null, null);
var openApi = result.getOpenAPI();
// now save it as yaml
var isV31 = true;
try {
var yaml = ObjectMapperFactory.createYaml(true).writeValueAsString(openApi);
System.out.println(yaml);
} catch (Exception e) {
e.printStackTrace();
}
}
}
output is:
openapi: 3.1.0
info:
title: Sample Pet Store App
contact:
name: API Support
url: https://www.example.com/support
email: [email protected]
x-myext:
key1: 1
license:
name: asassaas
extensions:
x-licence:
key1: 1
version: 1.0.1
summary: A pet store manager.
x-info:
key1: 1
servers:
- url: /
dependencies:
<dependencies>
<dependency>
<groupId>io.swagger.parser.v3</groupId>
<artifactId>swagger-parser</artifactId>
<version>2.1.22</version>
</dependency>
</dependencies>