Forum Discussion

Techtez's avatar
Techtez
Occasional Contributor
7 months ago

exampleSetFlag additional property

I am using Swagger in my RESTEasy project.

I am using the swagger-jaxrs2 version 2.1.12

  1. Swagger UI displays  GET api/{job-id} , POST api/{job-id}, DELETE api/{job-id} and GET api/restesy/{job-id} also along with my API's endpoints.
  2. In the openapi.json,         "schema" : { "type" : "string" , "exampleSetFlag" : false } is generating multiple times. So I am getting an error in the swagger editor that , " schema should not have additional properties, additionalProperty : exampleSetFlag

If I use swagger-jaxrs2 version 2.0.6, additionalProperties and extra endpoints are not generated, but the "info" section is not generated in the openapi.json. Getting error missingProperty :info

I would like to grow with the latest version, but how do I resolve generating of additionalProperty : exampleSetFlag and extra endpoints?

 

 

2 Replies

  • bella934's avatar
    bella934
    New Contributor

    Hello, Techtez 

     

    1. Resolving additionalProperty: exampleSetFlag Error
    The error regarding exampleSetFlag likely stems from incompatibilities between your Swagger configuration and the generated OpenAPI specification. This issue can be addressed as follows:

    a. Upgrade or Adjust Swagger Annotations
    Ensure you're using the appropriate annotations for Swagger compatibility. Double-check the annotations on your model and endpoints to avoid unnecessary fields like exampleSetFlag.

    b. Customize Schema Generation
    You can customize the schema generation by overriding Swagger's default schema behavior. To do this, implement a custom ModelConverter:

    java
    import io.swagger.v3.core.converter.ModelConverter;
    import io.swagger.v3.core.converter.ModelConverterContext;
    import io.swagger.v3.oas.models.media.Schema;

    public class CustomModelConverter implements ModelConverter {
        @Override
        public Schema<?> resolveSchema(io.swagger.v3.oas.models.media.Schema<?> schema, ModelConverterContext context) {
            schema.getExtensions().remove("exampleSetFlag");
            return schema;
        }
    }
    Register this custom model converter with your Swagger configuration.

    c. Exclude exampleSetFlag Globally
    In your Swagger setup, exclude the exampleSetFlag globally using configuration properties. For example:

    java
    SwaggerConfiguration config = new SwaggerConfiguration();
    config.setModelConverters(new CustomModelConverter());
    2. Extra Endpoints in Swagger UI
    If Swagger UI displays unintended endpoints, such as GET api/{job-id} or DELETE api/{job-id}, these may originate from:

    Unintentionally included resource classes.
    Default resources added by Swagger configuration.
    a. Check Swagger Resource Scanning
    Review your Application class or Swagger resource scanning setup. Limit the scanned resources to only your intended API endpoints:

    java
    @ApplicationPath("/api")
    public class RestApplication extends Application {
        @Override
        public Set<Class<?>> getClasses() {
            Set<Class<?>> resources = new HashSet<>();
            resources.add(MyApiResource.class); // Add your API resource classes explicitly
            return resources;
        }
    }
    b. Exclude Undesired Endpoints
    If the unwanted endpoints are generated automatically by RESTEasy or Swagger, you can explicitly filter them out using Swagger configuration or annotations.

    3. info Section Missing in OpenAPI.json
    When using Swagger version 2.0.6, the info section is missing. This section is essential in OpenAPI and can be explicitly defined in your Swagger configuration.

    Define the info Section in Swagger Config
    Add an OpenAPI bean to define the info section explicitly:

    java
    @OpenAPIDefinition(
        info = @Info(
            title = "My API",
            version = "1.0.0",
            description = "API for my RESTEasy project"
        )
    )
    public class SwaggerConfig {
        // Swagger configuration goes here
    }
    Ensure this configuration is picked up by your Swagger setup.

    4. Upgrade to Latest Version
    If you decide to use the latest version of swagger-jaxrs2 (2.1.12 or newer), ensure the following:

    Use a compatible version of swagger-ui to visualize the API.
    Test the openapi.json in the Swagger Editor for compliance.
    Validate all annotations and configurations to ensure they align with the OpenAPI 3.0 specification.
    5. Testing the Solution
    After applying the changes:

    Regenerate the openapi.json.
    Validate the openapi.json in the Swagger Editor.
    Verify the Swagger UI only displays the desired endpoints and resolves errors.

     

    Best Regards
    bella964

    • Techtez's avatar
      Techtez
      Occasional Contributor

      Hi Bella,

      Thanks for your response.

      When I use the swagger-jaxrs2 and swagger-core versions 2.2.26, it is resolved the additionalProperty: exampleSetFlag Error. Also using the latest swagger-ui.

      Regarding the Extra Endpoints in Swagger UI, how to disable the generating of Default resources ?

      @ApplicationPath("/serviceAPI")
      @OpenAPIDefinition(info= info(title = "REST API",
        version="Release 1.0",
        description="REST API description",
        servers= { @Server(url="/restInquiry")})
      public class RestApplication extends Application {

       @Override
       public Set>Class<?>> getClasses() {
         Set<class<?>> classes = new HashSet<>();
         classes.add (ApiController.class);
         classes.add (InquiryController.class);
         classes.add (OpenApiResource.class);
         return classes;
       }
      }

      How do we disable the displaying of extra endpoints?

      Thanks