Skip to content
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

Add xml support to openapi3 #4214

Draft
wants to merge 71 commits into
base: main
Choose a base branch
from
Draft

Conversation

skywing918
Copy link
Member

@skywing918 skywing918 commented Aug 20, 2024

  1. add test cases based on Examples
  2. add xml in OpenAPI3Schema type
  3. update schema-emitter logic for support xml object

@skywing918 skywing918 changed the title initial xml schema Add xml support to openapi3 Aug 20, 2024
@skywing918 skywing918 marked this pull request as draft August 28, 2024 07:06
packages/openapi3/src/schema-emitter.ts Outdated Show resolved Hide resolved
packages/openapi3/src/schema-emitter.ts Outdated Show resolved Hide resolved
// Resolve XML name
const xmlName = resolveEncodedName(program, prop, "application/xml");
const jsonName = resolveEncodedName(program, prop, "application/json");
if (xmlName && xmlName !== prop.name && xmlName !== jsonName) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if xmlName is undefined, prop.name = "bbb", jsonName == "aaa",
then we ignore json name.
is this expected?

packages/openapi3/src/schema-emitter.ts Show resolved Hide resolved
packages/openapi3/src/schema-emitter.ts Show resolved Hide resolved
packages/openapi3/src/schema-emitter.ts Outdated Show resolved Hide resolved
packages/openapi3/src/types.ts Show resolved Hide resolved
@@ -737,7 +865,8 @@ export class OpenAPI3SchemaEmitter extends TypeEmitter<

#applyConstraints(
type: Scalar | Model | ModelProperty | Union | Enum,
original: OpenAPI3Schema
original: OpenAPI3Schema,
ref: OpenAPI3Schema = {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to add ref? simply use 2nd parameter is enough?

packages/openapi3/src/schema-emitter.ts Show resolved Hide resolved
@skywing918
Copy link
Member Author

@timotheeguerin as you mentioned, it need set the xml name in items . but seems the xml name is not available if items,$ref existed.

@name("XmlPet")
model Pet {
  tags: Tag[];
}
@name("XmlTag")
model Tag {
  name: string;
}
Pet:
  type: object
  required:
    - tags
  properties:
    tags:
      type: array
      items:
        $ref: '#/components/schemas/Tag'
        xml:
          name: XmlTag
      xml:
        wrapped: true
  xml:
    name: XmlPet

image

@timotheeguerin
Copy link
Member

@timotheeguerin as you mentioned, it need set the xml name in items . but seems the xml name is not available if items,$ref existed.

@name("XmlPet")
model Pet {
  tags: Tag[];
}
@name("XmlTag")
model Tag {
  name: string;
}
Pet:
  type: object
  required:
    - tags
  properties:
    tags:
      type: array
      items:
        $ref: '#/components/schemas/Tag'
        xml:
          name: XmlTag
      xml:
        wrapped: true
  xml:
    name: XmlPet

image

You need to wrap the $ref in allOf like we do for nullable, description or other attributes

      properties:
        tags:
          type: array
          items:
            allOf:
              - $ref: '#/components/schemas/Tag'
            xml:
              name: XmlTag
          xml:
            wrapped: true

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.

3 participants