Open MercurieVV opened 5 years ago
The Aliases/Anchors &/* can be expanded before:
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import io.swagger.v3.core.util.Json;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.parser.OpenAPIV3Parser;
OpenAPI openAPI = new OpenAPIV3Parser().read("myApi.yaml");
String swaggerJson = Json.mapper().writeValueAsString(openAPI);
JsonNode jsonNodeTree = new ObjectMapper().readTree(swaggerJson);
String jsonAsYaml = new YAMLMapper().writeValueAsString(jsonNodeTree);
PrintWriter pw = new PrintWriter("myApi_expand.yaml");
pw.println(jsonAsYaml);
pw.close();
<dependency>
<groupId>io.swagger.parser.v3</groupId>
<artifactId>swagger-parser</artifactId>
<version>2.0.32</version>
</dependency>
Description
YAML have so called Aliases/Anchors
&
/*
. If I use them in swagger 3 project I got exception, cause Alias/Anchor feature was skipped. Its not directly Swagger issue, its seems Jackson. But you could switch YAML parsing library to any other. Btw. I didnt had this issue in Swagger 2. Heres Jackson issue: https://github.com/FasterXML/jackson-dataformats-text/issues/98Swagger-codegen version
3.0.4
Swagger declaration file content or url
Command line used for generation
It doesnt metter. It generic YAML processing issue. generate something
Steps to reproduce
1) generate any code from my yaml 2) You will get java.util.NoSuchElementException: No value present
Related issues/PRs
Suggest a fix/enhancement
Use another YAML parsing lib. From Jackson bug comments I see snakeyaml process this without problem