swagger-api / swagger-parser

Swagger Spec to Java POJOs
http://swagger.io
Apache License 2.0
786 stars 531 forks source link

Enum parsing failure #1315

Open apashchenkova opened 4 years ago

apashchenkova commented 4 years ago

swagger-core version: 1.5.24 jackson version: 2.9.7 swagger-parser version: 1.0.44

During parsing getting an exception:

java.lang.ClassCastException: com.fasterxml.jackson.databind.node.TextNode cannot be cast to com.fasterxml.jackson.databind.node.ArrayNode
    at io.swagger.util.PropertyDeserializer.getEnum(PropertyDeserializer.java:72)
    at io.swagger.util.PropertyDeserializer.argsFromNode(PropertyDeserializer.java:181)
    at io.swagger.util.PropertyDeserializer.propertyFromNode(PropertyDeserializer.java:330)
    at io.swagger.util.PropertyDeserializer.deserialize(PropertyDeserializer.java:138)
    at io.swagger.util.PropertyDeserializer.deserialize(PropertyDeserializer.java:40)
    at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:3600)
    at com.fasterxml.jackson.databind.ObjectMapper.convertValue(ObjectMapper.java:3524)
    at io.swagger.parser.util.SwaggerDeserializer.property(SwaggerDeserializer.java:1073)
    at io.swagger.parser.util.SwaggerDeserializer.definition(SwaggerDeserializer.java:907)
    at io.swagger.parser.util.SwaggerDeserializer.definitions(SwaggerDeserializer.java:746)
    at io.swagger.parser.util.SwaggerDeserializer.parseRoot(SwaggerDeserializer.java:115)
    at io.swagger.parser.util.SwaggerDeserializer.deserialize(SwaggerDeserializer.java:41)
    at io.swagger.parser.Swagger20Parser.convertToSwagger(Swagger20Parser.java:140)
    at io.swagger.parser.Swagger20Parser.parse(Swagger20Parser.java:156)
    at io.swagger.parser.SwaggerParser.parse(SwaggerParser.java:135)
    at io.swagger.parser.SwaggerParser.parse(SwaggerParser.java:129)

I've tried to upgrade versions as follows:

swagger-core version: 1.6.0 jackson version: 2.10.2 swagger-parser version: 1.0.49

but gets the same issue.

API:

swagger: '2.0'
info:
  version: 1.1.2
  title: API
produces:
  - application/json

paths:
  /devices:
    head:
      description: Get the total number of Device Types.
      parameters:
        - name: status
          in: query
          description: Device Type status filter.
          type: string
          enum: &DeviceStatus-enum
            - ACTIVE
            - ARCHIVED
      responses:
        204: 
          description: OK - Successful response
          headers:
              X-Total-Count:
                type: integer
    get:
      description: Get a list of supported Device Types.
      parameters:
        - name: status
          in: query
          description: Device Type status filter.
          type: string
          enum: *DeviceStatus-enum
      responses:
        200:
          description: Successful response
          headers:
              X-Total-Count:
                type: integer
                description: Total count of filtered Device Types without offset and limit parameters applied
          schema:
            type: array
            items:
              $ref: '#/definitions/DEVICE'

definitions:
  DEVICE:
    type: object
    properties:
      name:
        type: string
        description: Device model name
      status:
        type: string
        enum: *DeviceStatus-enum
        description: Device status
        default: ACTIVE
hkosova commented 4 years ago

@apashchenkova Please provide the full API definition that you tried to parse.

apashchenkova commented 4 years ago

@apashchenkova Please provide the full API definition that you tried to parse.

Please have a look at the issue description

webron commented 4 years ago

It's likely to be due to the anchor. A workaround would be... to not use an anchor.