Skip to content

XmlExampleGenerator does not properly handle properties of several numeric types #4672

@jbhelm

Description

@jbhelm
Description

When generating example XML content using the XmlExampleGenerator, properties that are BaseIntegerProperty (integer with no format), DecimalProperty, FloatProperty, or DoubleProperty will output an error for the value, even if the the property includes an example value.

Swagger-codegen version

master

Swagger declaration file content or url
swagger: '2.0'
info:
  title: 'XmlExampleGenerator BaseIntegerProperty example code'
  version: '1'
paths:
  '/test':
    get:
      produces: [ 'application/xml' ]
      responses:
        200:
          description: Success
          schema:
            type: object
            xml:
              name: 'test'
            properties:
              'int32':
                type: integer
                format: 'int32'
                example: 32
              'int64':
                type: integer
                format: 'int64'
                example: 64
              'integer':
                type: integer
                example: 1
              'number':
                type: number
              'float':
                type: number
                format: 'float'
                example: 0.0
              'double':
                type: number
                format: 'double'
                example: 0.0
Command line used for generation

Generate any docs that show the XML example output.

Steps to reproduce

Generate any docs that show the XML example output and you'll receive something along the lines of the following:

<test>
  <int32>32</int32>
  <int64>64</int64>
  <integer>not implemented io.swagger.models.properties.BaseIntegerProperty@e692af7f</integer>
  <number>not implemented io.swagger.models.properties.DecimalProperty@63b32949</number>
  <float>not implemented io.swagger.models.properties.FloatProperty@509ea33</float>
  <double>not implemented io.swagger.models.properties.DoubleProperty@6e01b9a8</double>
</test>

Note the first two work as expected because they have a format specified, so they are IntegerProperty which the XmlExampleGenerator handles correctly.

Related issues
Suggest a Fix

In XMLExampleGenerator::getExample():

  1. Every instanceof block first performs
if (property.getExample() != null) {
              return property.getExample().toString();
          } else {

Suggest calling this first before checking the property type; the property type only needs to be checked if there is no example value and a default needs to be generated.

  1. Add BaseIntegerProperty, DecimalProperty, FloatProperty, or DoubleProperty to the instanceof blocks.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions