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

Valid YAML Alias/Anchor features not supported fy Jackson #9156

Open
MercurieVV opened this issue Feb 8, 2019 · 1 comment
Open

Valid YAML Alias/Anchor features not supported fy Jackson #9156

MercurieVV opened this issue Feb 8, 2019 · 1 comment

Comments

@MercurieVV
Copy link

MercurieVV commented Feb 8, 2019

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:
FasterXML/jackson-dataformats-text#98

Swagger-codegen version

3.0.4

Swagger declaration file content or url
paths:
  /marketplaces/{marketplaceId}/claims:
    get:
      tags:
        - 'claims'
      summary: get Claims list
      operationId: getClaims
      parameters:
        - &marketplaceId
          name: marketplaceId
          in: path
          description: 'marketplaceId: darty, amazon-fr, amazon-de, amazon-com'
          required: true
          schema:
            type: string
  /marketplaces/{marketplaceId}/claims/{claimId}/messages:
    post:
      tags:
        - 'claims'
      summary: post Claim message
      operationId: postClaimMessage
      parameters:
        - *marketplaceId
        - name: claimId
          in: path
          required: true
          schema:
            type: string
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

@pkral3
Copy link

pkral3 commented May 4, 2022

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>

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