Skip to content

autonomouslogic/custom-spec-filter

Repository files navigation

Custom SpecFilter

GitHub release (latest by date) javadoc GitHub Workflow Status (branch) GitHub

A custom SpecFilter for the OpenAPI/Swagger.

Removes implementation arguments from method signatures

Some API implementations, like CDAP Netty, for which this filter was originally written, requires method signatures like this:

public void concatenate(HttpRequest req, HttpResponder res, @PathParam("str1") String str1, @PathParam("str2") String str2)

This results in the OpenAPI tools to register HttpRequest and HttpResponder as schemas in the resulting API spec. The Custom SpecFilter removes these entries from the method signatures before the spec is written.

Sorts everything by name

When adding and removing API calls, the OpenAPI spec is sorted in whatever internal representation the plugin has. This means that when you add new things, it'll also move things around seemingly at random. If your spec is checked into source control, this can make for annoying diffs. The Custom SpecFilter makes sure everything is sorted before writing the spec.

Usage

Include the Custom SpecFilter as a normal dependency and configure your the filterClass property of your respective plugin:

Gradle:

resolve {
	filterClass = "com.autonomouslogic.customspecfilter.CustomSpecFilter"
}

Maven:

<project>
    <build>
        <plugins>
            <plugin>
                <groupId>io.swagger.core.v3</groupId>
                <artifactId>swagger-maven-plugin</artifactId>
                <configuration>
                    <filterClass>com.autonomouslogic.customspecfilter.CustomSpecFilter</filterClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

A number of schema names are removed by default. To override the default and customise which schemas are removed, create a file in the root of your project called customspecfilter.json:

{
  "filteredSchemas": [
    "BodyConsumer",
    "DecoderResult",
    "HttpMethod",
    "HttpRequest",
    "FullHttpRequest",
    "HttpVersion",
    "HttpResponder"
  ]
}

Resources

Versioning

Custom SpecFilter follows semantic versioning.

License

Custom SpecFilter is licensed under the MIT-0 license.

Status

Type Status
LGTM Language grade: Java Total alerts
CodeClimate Maintainability
SonarCloud Maintainability Rating Code Smells
Libraries.io Libraries.io dependency status for latest release
Snyk Known Vulnerabilities
Synatype Lift link