swagger-api / swagger-api/swagger-core
BUG Null-typed extensions elements disappear when creating yaml
Open
Nobody has claimed this yet.
backlog
- Dominant language
- Java
- Stars
- 7.5k
- Forks
- 2.3k
- Avg merge
- 18h 1m
- Merged PRs (30d)
- 10
Description
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: support@example.com
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: support@example.com
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>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided reproducer and inspect ObjectMapperFactory.createYaml(true), focusing on serialization of OpenAPI extensions and null-valued entries. Done means the generated YAML preserves extension fields whose values are null and does not emit an unwanted extensions wrapper under license.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100