Skip to content

Commit

Permalink
WIP: add JavaDocs for new builder API
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Edgar <michael@xlate.io>
  • Loading branch information
MikeEdgar committed Mar 15, 2024
1 parent d3020d9 commit ebcc803
Showing 1 changed file with 92 additions and 1 deletion.
93 changes: 92 additions & 1 deletion core/src/main/java/io/smallrye/openapi/api/SmallRyeOpenAPI.java
Expand Up @@ -104,46 +104,137 @@ public static class Builder {
private Builder() {
}

/**
* Set the MicroProfile Config to be used when building the OpenAPI
* model. When not set, the builder will obtain a Config instance using
* {@link ConfigProvider#getConfig()} with the
* {@linkplain #withApplicationClassLoader(ClassLoader) application
* class loader}.
*
* @param config
* Config instance, nulls not allowed
* @return this builder
*/
public Builder withConfig(Config config) {
this.config = Objects.requireNonNull(config);
return this;
}

/**
* Set the application ClassLoader to be used when building the OpenAPI
* model.
*
* @param classLoader
* ClassLoader instance, nulls not allowed
* @return this builder
*/
public Builder withApplicationClassLoader(ClassLoader classLoader) {
this.applicationClassLoader = Objects.requireNonNull(classLoader);
return this;
}

/**
* Set an initial model used when building the OpenAPI model. The
* elements in this model will be overridden by any conflicting elements
* in models generated by the builder.
*
* @param initialModel
* initial OpenAPI model
* @return this builder
*/
public Builder withInitialModel(OpenAPI initialModel) {
this.initialModel = initialModel;
return this;
}

/**
* Enable (true) or disable (false) the lookup and use of an
* OASModelReader. Default is true.
*
* @param enableModelReader
* true if the model reader should be loaded and called,
* otherwise false.
* @return this builder
*/
public Builder enableModelReader(boolean enableModelReader) {
this.enableModelReader = enableModelReader;
return this;
}

/**
* Enable (true) or disable (false) the lookup and use of the standard
* static OpenAPI files (e.g. {@code META-INF/openapi.(json|yaml|yml)}.
* Default is true.
*
* @param enableStandardStaticFiles
* true if the standard static files should be loaded and
* included, otherwise false.
* @return this builder
*/
public Builder enableStandardStaticFiles(boolean enableStandardStaticFiles) {
this.enableStandardStaticFiles = enableStandardStaticFiles;
return this;
}

/**
* Enable (true) or disable (false) the lookup and use of the standard
* OASFilter. Default is true.
*
* @param enableStandardFilter
* true if the filter should be loaded and called, otherwise
* false.
* @return this builder
*/
public Builder enableStandardFilter(boolean enableStandardFilter) {
this.enableStandardFilter = enableStandardFilter;
return this;
}

/**
* Enable (true) or disable (false) setting default values for the
* OpenAPI properties listed below. Default is true.
*
* <ul>
* <li>Create an empty {@code paths} object if none specified
* <li>Set a generated value for {@code info.title} if none specified
* <li>Set a generated value for {@code info.version} if none specified
* <li>Set a default value for {@code openapi} (the specification
* version) if none specified. E.g. 3.0.3
* </ul>
*
* @param defaultRequiredProperties
* true if default values should be set when necessary,
* otherwise false.
* @return this builder
*/
public Builder defaultRequiredProperties(boolean defaultRequiredProperties) {
this.defaultRequiredProperties = defaultRequiredProperties;
return this;
}

/**
* Provide a resource locator function that when given a String path for
* a static file will return a URL that may be used to load the
* resource. This function is intended to support environments where the
* resource is not on the class path and an alternate loading approach
* is necessary, for example using a ServletContext.
*
* @param resourceLocator
* @return this builder
*/
public Builder withResourceLocator(Function<String, URL> resourceLocator) {
this.resourceLocator = resourceLocator;
return this;
}

/**
* Provide a custom static file that is not one of those in the standard locations
* or with a standard name. The user of this builder is responsible for closing the stream
* after {@linkplain #build()} has been invoked.
*
* @param customStaticFile
* @return
*/
public Builder withCustomStaticFile(InputStream customStaticFile) {
this.customStaticFile = customStaticFile;
return this;
Expand Down Expand Up @@ -225,7 +316,7 @@ public <V, A extends V, O extends V, AB, OB> SmallRyeOpenAPI build() {
: Thread.currentThread().getContextClassLoader();

OpenApiConfig buildConfig = OpenApiConfig.fromConfig(Optional.ofNullable(this.config)
.orElseGet(ConfigProvider::getConfig));
.orElseGet(() -> ConfigProvider.getConfig(appClassLoader)));
IOContext<V, A, O, AB, OB> io = IOContext.forJson(JsonIO.newInstance(buildConfig));
OpenAPIDefinitionIO<V, A, O, AB, OB> modelIO = new OpenAPIDefinitionIO<>(io);
FilteredIndexView filteredIndex = new FilteredIndexView(index, buildConfig);
Expand Down

0 comments on commit ebcc803

Please sign in to comment.