Skip to content

OpenAPI v2 converter: java.lang.IllegalArgumentException with allOf and discriminator #740

Description

@jmini

There seems to be a problem when this spec (OAS2) is parsed:

swagger: "2.0"
info:
  version: "2"
  title: "TRACT Billing API"
basePath: "/billing/2"
consumes:
- "application/json"
produces:
- "application/json"
paths:
  /actions:
    get:
      tags:
      - "Action"
      summary: "Get actions"
      operationId: "queryActions"
      produces:
      - "application/json"
      parameters:
      - name: "id"
        in: "query"
        description: "The internal ID of the object."
        required: false
        type: "string"
      responses:
        200:
          description: "Success"
          schema:
            type: "array"
            items:
              $ref: "#/definitions/Action"
          headers:
            ETag:
              type: "string"
              description: "The standard ETag HTTP header."
            X-total-count:
              type: "integer"
              format: "int64"
              description: "The total results for the particular query. Used to drive\
                \ paging requests."
            X-element-count:
              type: "integer"
              format: "int64"
              description: "The number of elements returned in the current request.\
                \ Used to drive paging requests."
            X-total-pages:
              type: "integer"
              format: "int64"
              description: "The total number of pages that can be requested. Used\
                \ to drive paging requests."
        400:
          description: "Bad request."
        default:
          description: "Unknown error."
      x-swagger-router-controller: "ActionsController"
definitions:
  Entity:
    type: "object"
    properties:
      id:
        type: "string"
        example: "1438752"
        description: "(unique_key) The ID of the entity."
        readOnly: true
    title: "Entity"
    description: "A base object for all API entities."
  Action:
    title: "Action"
    allOf:
    - $ref: "#/definitions/Entity"
    - type: "object"
      required:
      - "action_type"
      discriminator: "action_type"
      properties:
        name:
          type: "string"
          description: "The name of the action."
          readOnly: true
        enabled:
          type: "boolean"
          description: "Specifies whether the action is enabled."
          readOnly: true
        friendly_name:
          type: "string"
          description: "The optional additional name of the action."
          readOnly: true
        supports_approval:
          type: "boolean"
          description: "Specifies whether the action supports approval."
          readOnly: true
        action_type:
          $ref: "#/definitions/ActionType"
  ActionType:
    type: "string"
    title: "ActionType"
    description: "Indicates the type of action that occurs."
    enum:
    - "agreement"
    - "agreement-service"
    - "bill-cycle-run"
    - "bill-batch-run"
    - "billing-account"
    - "counter"
    - "credit-adjustment"
    - "disbursement"
    - "invoice"
    - "payment"
    - "product-sale"
    - "remote-prepaid-register"
    - "sales-order"
    - "service"
    - "service-cfv"
    - "system-notification"
    - "usage-rule"
    x-swagger-router-model: "ActionTypeDto"

Test code:

import io.swagger.parser.OpenAPIParser;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.parser.core.models.ParseOptions;

import java.util.Map;
import java.util.Map.Entry;

public class SwaggerParserTest {

    public static void main(String[] args) {
        String inputSpec = "oas2.yaml";

        final OpenAPIParser openApiParser = new OpenAPIParser();
        final ParseOptions options = new ParseOptions();
        options.setResolve(true);
        options.setFlatten(true);
        final OpenAPI openAPI = openApiParser.readLocation(inputSpec, null, options).getOpenAPI();
}
}

Dependency:

<groupId>io.swagger.parser.v3</groupId>
<artifactId>swagger-parser</artifactId>
<version>2.0.1</version>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions