Skip to content

resolve-schema-properties is not replacing tokens from properties file #1552

Closed
@nigelsim

Description

@nigelsim

Describe the bug
I am migrating from SpringFox to SpringDoc, using org.springdoc:springdoc-openapi-webmvc-core:1.6.6.

All of my property descriptions are in a properties file that is used in the Schema using ${Model.property}. In SpringFox this was @ApiModelProperty(value = "${Generic.name}"), and in SpringDoc this is @Schema(description = "${Generic.name}").

Following the FAQ I set springdoc.api-docs.resolve-schema-properties: true, however, I still get the unresolved tokens in the output. (Also, looking at the code I can't see where this config parameter is used).

Debugging, I can see that the MessageConverter being passed into PropertyResolverUtils is an empty message converter.

I am running SpringDoc from within an test, which is how I used to run SpringFox. This has tended to be more reliable, and quicker, than starting a background copy of the app like the Gradle/Maven plugin does.

To Reproduce

application.properties

springdoc:
  api-docs:
    enabled: true
    resolve-schema-properties: true

DTO

@Data
public class PersonDto {
    @Schema(description = "${Generic.id}", required = true)
    private Long id;
}

swagger-messages.properties

Generic.id=The database ID for this entity instance

Code generation test

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK, classes = PortalApplication.class)
@PropertySources({@PropertySource("classpath:swagger-messages.properties"),
        @PropertySource("classpath:version.properties")})
@AutoConfigureMockMvc
@Import(UpdateSwaggerModels.SwaggerConfiguration.class)
@WithMockUser
public class UpdateSwaggerModels {
    @TestConfiguration()
    public static class SwaggerConfiguration {
        @Bean
        public GroupedOpenApi externalApi() {
            return GroupedOpenApi.builder()
                    .group("default")
                    .packagesToScan("io.portal.web.extapi")
                    .build();
        }

    @Autowired
    private MockMvc mockMvc;

    @Autowired
    private List<GroupedOpenApi> groupList;

    @Tag("OpenAPI")
    @Test
    public void generateOpenApi() throws Exception {
        for (GroupedOpenApi group : groupList) {
            File outputFile = new File("api-" + group.getGroup() + ".json");
            try (FileWriter w = new FileWriter(outputFile)) {
                this.mockMvc.perform(get("/v3/api-docs/" + group.getGroup()).accept(MediaType.APPLICATION_JSON))
                        .andDo(result -> w.write(result.getResponse().getContentAsString()))
                        .andExpect(status().isOk());
            }
        }
    }

}

Expected behavior

  • Tokens to be replaced with text from the property

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions