Skip to content

Fix: Property resolution for extensions within @OpenAPIDefinition Info object #3039

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

limehee
Copy link
Contributor

@limehee limehee commented Jul 7, 2025

Fixes #3032

Problem:
Property placeholders (${...}) were not being resolved within the extensions attribute of @OpenAPIDefinition's info object. This was inconsistent, as placeholders in other @Info attributes, such as title and version, were resolving correctly.

Example Code:

@OpenAPIDefinition(
    info = @Info(
          title = "OpenAPI Demo",
          version = "${springdoc.version}", // This value was resolved correctly
          extensions = @Extension(properties = @ExtensionProperty(name = "x-created-ts", value = "${git.build.time}")) // This value was NOT resolved
    ))

Actual JSON Output:

{
  "info": {
    "title": "OpenAPI Demo",
    "version": "v1",
    "x-created-ts": "${git.build.time}" // Expected: "2024-07-08T12:00:00Z" (resolved value)
  },
  ...
}

Root Cause:
The root cause of this issue was two-fold, involving problems in both property resolution logic and its invocation:

  1. Incomplete Resolution in PropertyResolverUtils:
    The resolveExtensions method was not designed to resolve simple String values of top-level extension properties. It correctly handled the resolution of extension keys and the key-value pairs within nested maps, but it skipped the crucial step of resolving the extension's primary String value itself.

  2. Conditional Logic in OpenAPIService:
    The invocation of the property resolution logic for @OpenAPIDefinition's info extensions was wrapped in a conditional check (propertyResolverUtils.isResolveExtensionsProperties()). This internal property defaults to false, which prevented the necessary resolution logic from being triggered in a standard configuration. This created an inconsistency with how other @Info attributes were handled, as their resolution was not similarly gated.


Solution:
This PR addresses both identified issues to ensure consistent and predictable behavior:

  1. Enhanced PropertyResolverUtils:
    The resolveExtensions method has been updated to properly resolve top-level String values within the extensions map. This was achieved by adding a specific check for String instances:
else if (value instanceof String valueAsString) {
    String valueResolved = resolve(valueAsString, locale);
    extensionsResolved.put(keyResolved, valueResolved);
}
  1. Unconditional Resolution in OpenAPIService:
    The conditional check for isResolveExtensionsProperties() has been removed from the resolveProperties(Info info, ...) method. This ensures that property resolution for extensions is always applied, making the behavior consistent with all other @Info attributes.

@limehee limehee changed the title Fix: Property resolution for extensions within @OpenAPIDefinition Info object Fix: Property resolution for extensions within @OpenAPIDefinition Info object Jul 7, 2025
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.

Property resolution not working for extension
1 participant