swagger-api / swagger-api/swagger-parser

Enum parsing failure

Open
#1,315 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
867
Forks
560
Avg merge
2d 21h
Merged PRs (30d)
7

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at io.swagger.util.PropertyDeserializer.getEnum(PropertyDeserializer.java:72) and reproduce the failure with the supplied Swagger 2.0 YAML, including the aliased enum values. Trace the node type passed through SwaggerDeserializer and confirm the parser handles this input without the ClassCastException; add or update a regression test if the repository’s test location is identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.