Skip to content

Conversation

newtork
Copy link
Contributor

@newtork newtork commented Jun 16, 2025

Context

https://github.com/SAP/ai-sdk-java-backlog/issues/273

Offers an opt-in feature to enable preprocessing of OpenAPI:

When fixResponseSchemaTitles=true then the following title properties are added dynamically.
components:
  responses:
    NotFound:
      description: The specified resource was not found
      content:
        application/json:
          schema:
+           title: NotFound Content
            type: object
            properties:
              message:
                type: string
                example: Resource not found
    ServiceUnavailable:
      description: The service is currently unavailable
      content:
        application/json:
          schema:
+           title: ServiceUnavailable application/json
            type: object
            properties:
              message:
                type: string
                example: Resource not found
        application/xml:
          schema:
+           title: ServiceUnavailable application/xml
            type: object
            properties:
              message:
                type: string
                example: Resource not found

The result is class names being fixed:

- InlineObject.java
- InlineObject1.java
- InlineObject2.java
+  NotFoundContent.java
+  ServiceUnavailableApplicationJson.java
+  ServiceUnavailableApplicationXml.java

The important side-effect:

  • Class naming stays deterministic.

Feature scope:

Definition of Done

  • Functionality scope stated & covered
  • Tests cover the scope above
  • Error handling created / updated & covered by the tests above
  • Documentation updated
  • Release notes updated

@newtork newtork added please merge Request to merge a pull request please review Request to review a pull request labels Jun 16, 2025
@newtork newtork changed the title feat: Fix class name generation for inline-object of //component/response schemas feat: (OpenAPI) Fix class name generation for inline-object of //component/response schemas Jun 17, 2025
mediaContent.forEach(( mediaType, content ) -> {
final Schema<?> schema = content.getSchema();
if( schema != null && schema.getTitle() == null ) {
schema.setTitle(key + " " + (mediaContent.size() > 1 ? mediaType : "Content"));
Copy link
Member

Choose a reason for hiding this comment

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

(Minor)

I don't like adding "Content" to the title if there is only one mediaContent. I would rather always use the mediaType in the title. If in the future a second mediaType is added in the spec then using "Content" will lead to avoidable breaking changes: the already existing title (and thus the existing classname) would change from XYZ Content to e.g. XYZ plain/text.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Generally I agree to that concern. However in 99% of cases there is only one media-type: application/json.
And this would result in many (many) classes being generated with ApplicationJson name suffix. That looks really bad.

We might consider the following suffix-options:
1️⃣ $mediaType
2️⃣ n=1 -> "Content", else -> $mediaType
3️⃣ n=1 -> "Payload", else -> $mediaType
4️⃣ n=1 -> "", else -> $mediaType

Copy link
Member

@Jonas-Isr Jonas-Isr Jun 24, 2025

Choose a reason for hiding this comment

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

If we are fairly certain that this will not come up often (which I am not able to asses, so I believe you), then I am fine with this approach. I also see that having ApplicationJson appended to many class names does not add much readability. I would then, however probably use version 4️⃣ since if we assume that there will mostly be only one media type, then we do not need any special suffix IMO.

Copy link
Contributor Author

@newtork newtork Jul 2, 2025

Choose a reason for hiding this comment

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

I assumed 4️⃣ was not possible due to naming conflicts but it works! No conflicts.

Copy link
Member

@Jonas-Isr Jonas-Isr left a comment

Choose a reason for hiding this comment

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

LGTM

@newtork newtork merged commit 2391f2a into main Jul 4, 2025
14 checks passed
@newtork newtork deleted the fix-inline-object-component-response-schema branch July 4, 2025 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
please merge Request to merge a pull request please review Request to review a pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants