Skip to content

always use @JacksonXmlElementWrapper and read xml data from reference… #5371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

jzrebiec
Copy link

@jzrebiec jzrebiec commented Feb 19, 2020

Hello All,

This pull request adds:

  • always writes JacksonXmlElementWrapper even if xml.wrapped is false, because useWrapping is true from Jackson 2.1
  • get xml properties from referenced schema.

Here is example of yaml:

openapi: 3.0.0
info:
  title: API
  version: 1.0.0

paths:
  /:
    post:
      requestBody:
        required: true
        content:
          application/xml:
            schema:
              $ref: '#/components/schemas/Request'
      responses:
        '200':
          description: OK

components:
  schemas:
    Request:
      type: object
      properties:
        simpleAttribute:
          type: string
          xml:
            attribute: true
            name: ATTR
        refAttribute:
          $ref: '#/components/schemas/RefAttribute'
        simpleNode:
          type: object
          properties:
            prop1:
              type: string
            prop2:
              type: string
          xml:
            name: NODE
        refNode:
          $ref: '#/components/schemas/RefNode'
        simpleArray:
          type: array
          items:
            type: string
            xml:
              name: ARR_ITEM
        simpleWrappedArray:
          type: array
          items:
            type: string
            xml:
              name: ARR_ITEM
          xml:
            wrapped: true
            name: WRAPPED_ARRAY
        nodeArray:
          type: array
          items:
            $ref: '#/components/schemas/RefNode'
        wrappedNodeArray:
          type: array
          items:
            $ref: '#/components/schemas/RefNode'
          xml:
            wrapped: true
            name: WRAPPED_NODE_ARRAY
      xml:
        name: Request

    RefAttribute:
      type: string
      enum: [A, B, C]
      xml:
        name: REF_ATTR
        attribute: true

    RefNode:
      type: object
      properties:
        prop1:
          type: string
        prop2:
          type: string
      xml:
        name: REF_NODE

   

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project before.
  • Run the shell script(s) under ./bin/ (or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).
  • File the PR against the correct branch: master, 4.3.x, 5.0.x. Default: master.
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.
    @bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @bkabrda (2020/01)

@jzrebiec jzrebiec force-pushed the bugfix/proper-xml-support branch 2 times, most recently from e112d0b to b75335f Compare February 20, 2020 18:39
@jzrebiec jzrebiec force-pushed the bugfix/proper-xml-support branch 2 times, most recently from 023fb2b to 91add2e Compare February 21, 2020 08:23
@jzrebiec
Copy link
Author

jzrebiec commented Mar 6, 2020

Hello,

Can anyone look into this?

@RockyMM
Copy link
Contributor

RockyMM commented Jun 30, 2020

@jzrebiec Czesc, can you resolve conflicts? I will try to get the attention of project maintainers. Thanks!

@jzrebiec jzrebiec force-pushed the bugfix/proper-xml-support branch from 91add2e to 6a7b60a Compare August 10, 2020 11:51
@jzrebiec
Copy link
Author

@RockyMM Hi, I have just rebased the branch

@commievid
Copy link

Would definitely like this to be in soon, we had some head scratching around the XML and Spring!

@RockyMM
Copy link
Contributor

RockyMM commented Oct 13, 2020

Ah, life... Too much time spent on too many things :D

I am terribly sorry @jzrebiec , would you mind rebasing your commits again? :D

@jzrebiec
Copy link
Author

jzrebiec commented Jan 7, 2021

@RockyMM Unfortunately, I changed a project, so I don't need the changes anymore. If You want (and have time), feel free to take over the PR.

@scholzi100
Copy link

scholzi100 commented Jan 22, 2021

PR looks good, used it in a project. @RockyMM @jzrebiec looks like PR needs to be rebased and it needs to get some attention from openapi-generator.

@mutyasaisrikar
Copy link

@scholzi100 @RockyMM @jzrebiec, It would be very helpful if we can merge these changes.

@rkurucz9
Copy link

I would be grateful if these helpful changes could be merged.

@RockyMM
Copy link
Contributor

RockyMM commented Dec 4, 2022

I might have some capacity in December to check this issue. Don't hold your hopes too high though 😅

martin-mfg added a commit to martin-mfg/openapi-generator that referenced this pull request Apr 3, 2023
wing328 pushed a commit that referenced this pull request Jun 9, 2023
…d schema, updated (#15115)

* always use @JacksonXmlElementWrapper and read xml data from referenced schema

based on #5371

* run generate-samples.sh

* suggestion: remove comment with empty name
makru86 pushed a commit to makru86/openapi-generator that referenced this pull request Jun 12, 2023
…d schema, updated (OpenAPITools#15115)

* always use @JacksonXmlElementWrapper and read xml data from referenced schema

based on OpenAPITools#5371

* run generate-samples.sh

* suggestion: remove comment with empty name
fmoraespadtec pushed a commit to padteclab/openapi-generator that referenced this pull request Jun 26, 2023
…d schema, updated (OpenAPITools#15115)

* always use @JacksonXmlElementWrapper and read xml data from referenced schema

based on OpenAPITools#5371

* run generate-samples.sh

* suggestion: remove comment with empty name
Philzen added a commit to Philzen/openapi-generator that referenced this pull request May 22, 2024
This was slightly inspired by @jzrebiec via PR OpenAPITools#5371.

Wrapping is the default since Jackson 2.1 – so explicitly rendering
this will:
- make generated model work out-of-the-box in Jackson 2.0 for instance
- ensure the models still work if the local `XmlWrapper` was
  configured with `useXmlWrapper(false)`
Philzen added a commit to Philzen/openapi-generator that referenced this pull request May 22, 2024
This was slightly inspired by @jzrebiec via PR OpenAPITools#5371.

Wrapping is the default since Jackson 2.1 – so explicitly rendering
this will:
- make generated model work out-of-the-box in Jackson 2.0 for instance
- ensure the models still work if the local `XmlWrapper` was
  configured with `useXmlWrapper(false)`
Philzen added a commit to Philzen/openapi-generator that referenced this pull request May 22, 2024
This was slightly inspired by @jzrebiec via PR OpenAPITools#5371.

Wrapping is the default since Jackson 2.1 – so explicitly rendering
this will:
- make generated model work out-of-the-box in Jackson 2.0 for instance
- ensure the models still work if the local `XmlWrapper` was
  configured with `useXmlWrapper(false)`
Philzen added a commit to Philzen/openapi-generator that referenced this pull request May 23, 2024
This was slightly inspired by @jzrebiec via PR OpenAPITools#5371.

Wrapping is the default since Jackson 2.1 – so explicitly rendering
this will:
- make generated model work out-of-the-box in Jackson 2.0 for instance
- ensure the models still work if the local `XmlWrapper` was
  configured with `useXmlWrapper(false)`
Philzen added a commit to Philzen/openapi-generator that referenced this pull request Jun 6, 2024
This was slightly inspired by @jzrebiec via PR OpenAPITools#5371.

Wrapping is the default since Jackson 2.1 – so explicitly rendering
this will:
- make generated model work out-of-the-box in Jackson 2.0 for instance
- ensure the models still work if the local `XmlWrapper` was
  configured with `useXmlWrapper(false)`
Philzen added a commit to Philzen/openapi-generator that referenced this pull request Jun 6, 2024
This was slightly inspired by @jzrebiec via PR OpenAPITools#5371.

Wrapping is the default since Jackson 2.1 – so explicitly rendering
this will:
- make generated model work out-of-the-box in Jackson 2.0 for instance
- ensure the models still work if the local `XmlWrapper` was
  configured with `useXmlWrapper(false)`
@Philzen
Copy link
Contributor

Philzen commented Jun 6, 2024

As the relevant changes to DefaultCodegen.java from this PR were merged via #15115, closing this PR for now.

@Philzen Philzen closed this Jun 6, 2024
Philzen added a commit to Philzen/openapi-generator that referenced this pull request Jun 6, 2024
This was slightly inspired by @jzrebiec via PR OpenAPITools#5371.

Wrapping is the default since Jackson 2.1 – so explicitly rendering
this will:
- make generated model work out-of-the-box in Jackson 2.0 for instance
- ensure the models still work if the local `XmlWrapper` was
  configured with `useXmlWrapper(false)`
Philzen added a commit to Philzen/openapi-generator that referenced this pull request Jun 6, 2024
This was slightly inspired by @jzrebiec via PR OpenAPITools#5371.

Wrapping is the default since Jackson 2.1 – so explicitly rendering
this will:
- make generated model work out-of-the-box in Jackson 2.0 for instance
- ensure the models still work if the local `XmlWrapper` was
  configured with `useXmlWrapper(false)`
Philzen added a commit to Philzen/openapi-generator that referenced this pull request Jun 13, 2024
This was slightly inspired by @jzrebiec via PR OpenAPITools#5371.

Wrapping is the default since Jackson 2.1 – so explicitly rendering
this will:
- make generated model work out-of-the-box in Jackson 2.0 for instance
- ensure the models still work if the local `XmlWrapper` was
  configured with `useXmlWrapper(false)`
Philzen added a commit to Philzen/openapi-generator that referenced this pull request Jun 13, 2024
This was slightly inspired by @jzrebiec via PR OpenAPITools#5371.

Wrapping is the default since Jackson 2.1 – so explicitly rendering
this will:
- make generated model work out-of-the-box in Jackson 2.0 for instance
- ensure the models still work if the local `XmlWrapper` was
  configured with `useXmlWrapper(false)`
wing328 pushed a commit that referenced this pull request Jun 15, 2024
…apping=false, JAXB+Jackson namespaces (#18870)

* Fix XML annotations on model properties (JavaSpring)

* generate JAXB annotations for attributes and elements

* generate wrapper annotations (JAXB and Jackson)

* use XML config from items for annotations of containers

* Add test for Jackson XML wrapper correctness

* Add additional test cases to cover all xml applications in spec

Test now covers all use cases described in
- https://web.archive.org/web/20240424203304/https://swagger.io/docs/specification/data-models/representing-xml/
- https://spec.openapis.org/oas/v3.0.0#xml-arrays

* Fix basename used instead of xmlName when items.xmlName is unset

See last example in spec: https://spec.openapis.org/oas/v3.0.0#xml-arrays

* Harmonize spacing between Annotation attribute name and value

* Refactor and group JAXB vs. Jackson XML annotations, only generate latter if enabled

This is in line with the way the class annotations in `xmlAnnotations.mustache`
are rendered – which only renders the `@Jackson`… xml annotations if
additionalProperty jackson is true.

Also reorder annotation attributes in the following order:
- localName/name
- namespace (optional)
- isAttribute/useWrapping (optional)

* Explicitly render `useWrapping = true` to @JacksonXmlElementWrapper

This was slightly inspired by @jzrebiec via PR #5371.

Wrapping is the default since Jackson 2.1 – so explicitly rendering
this will:
- make generated model work out-of-the-box in Jackson 2.0 for instance
- ensure the models still work if the local `XmlWrapper` was
  configured with `useXmlWrapper(false)`

* Move xml test spec to java resources folder (not spring specific)

* Make test class name match class-under-test

This makes discovery & cross-navigation in IDE easier.

* Add complete xml annotations test for Java generators

* Fix Java PKMST generator not generating @JacksonXmlElementWrapper

* Fix Java microprofile generator missing @JacksonXmlRootElement

* Fix Java microprofile generator not using wrapper annotations and namespaces

* Fix Java Micronaut Client creating invalid (unclosed) @XmlAttribute annotations

* Fix Micronaut Client using wrong localName for @JacksonXmlElementWrapper

* Fix Micronaut client rendering @JacksonXmlProperty annotation twice

* Make Java Micronaut render @JacksonXmlElementWrapper(useWrapping=false) for non-wrapped elements

* Fix Jackson element using `xml.name` when it should be `items.xml.name`

Closes #5989
Closes #3223
Relates to #9371

* Fix JAXB element using `baseName` instead of `xmlName` when items.xmlName is unset

* Remove XML generation debug output from templates

* Remove redundant newline between XML class annotations and class

Brings the SpringCodegen in line with other Java Codegen's

* Remove redundant newline between XML setter annotations and setter

* Fix multiline JavaDoc block indentation and format

* Simplify / condense xml annotation template into single lines

May look a bit more complex, but cuts out a lot of repetitiveness.
Also reorders annotation attributes in the following order:
- localName/name
- namespace (optional)
- isAttribute/useWrapping (optional)

* Harmonize spacing between Annotation attribute name and value

* Remove unused jackson_annotations partial

Was not referenced anywhere in java-helidon resources folder

---------

Co-authored-by: Christian Schuster <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants