swagger-inflector icon indicating copy to clipboard operation
swagger-inflector copied to clipboard

XML Example can't be generated if last property is an attribute

Open jweisman opened this issue 5 years ago • 2 comments

Given the below pet.yaml definition, when the favorite property of the Tag object is defined first, the XML example is generated correctly. When the favorite property is last, the following error is thrown:

javax.xml.stream.XMLStreamException: Trying to write an attribute when there is no open start element.
	at com.ctc.wstx.sw.BaseStreamWriter.throwOutputError(BaseStreamWriter.java:1584)
	at com.ctc.wstx.sw.BaseStreamWriter.reportNwfStructure(BaseStreamWriter.java:1613)
	at com.ctc.wstx.sw.BaseNsStreamWriter.writeAttribute(BaseNsStreamWriter.java:231)
	at io.swagger.oas.inflector.examples.XmlExampleSerializer.writeTo(XmlExampleSerializer.java:160)
	at io.swagger.oas.inflector.examples.XmlExampleSerializer.writeTo(XmlExampleSerializer.java:81)
	at io.swagger.oas.inflector.examples.XmlExampleSerializer.writeTo(XmlExampleSerializer.java:135)
	at io.swagger.oas.inflector.examples.XmlExampleSerializer.writeTo(XmlExampleSerializer.java:81)
	at io.swagger.oas.inflector.examples.XmlExampleSerializer.serialize(XmlExampleSerializer.java:39)
	at MakeSwaggerExamples.main(MakeSwaggerExamples.java:61)
Exception in thread "main" java.lang.NullPointerException
	at java.io.StringReader.<init>(StringReader.java:50)
	at MakeSwaggerExamples.main(MakeSwaggerExamples.java:67)
Pet:
  type: object
  required:
    - name
    - photoUrls
  properties:
    id:
      type: integer
      format: int64
    category:
      $ref: './category.yaml#/Category'
    name:
      type: string
      example: doggie
    photoUrls:
      type: array
      xml:
        name: photoUrl
        wrapped: true
      items:
        type: string
    tag:
      type: array
      xml:
        name: tags
        wrapped: true
      items:
        $ref: '#/Tag'
        xml:
          name: tag
    status:
      type: string
      description: pet status in the store
      enum:
        - available
        - pending
        - sold
  xml:
    name: Pet
Tag:
  type: object
  properties:
    favorite:
      type: boolean
      xml:
        attribute: true
    id:
      type: integer
      format: int64
    name:
      type: string
  xml:
    name: tag       

jweisman avatar Mar 04 '19 15:03 jweisman

hi @jweisman which version of openapi are you using, if you can share the full spec will be great. thanks

gracekarina avatar Oct 05 '19 00:10 gracekarina

Hi @gracekarina - I'm using OpenAPI 3.0. The spec I shared here can reproduce the issue. Does it not reproduce for you? Thanks!

jweisman avatar Dec 26 '19 14:12 jweisman