Skip to content

Commit

Permalink
Merge pull request quarkusio#44431 from phillip-kruger/filename-openapi
Browse files Browse the repository at this point in the history
Add option to name stored openapi files
  • Loading branch information
geoand authored Nov 12, 2024
2 parents 52286bf + 0611099 commit c41dfd6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public final class SmallRyeOpenApiConfig {
@ConfigItem
public Optional<Path> storeSchemaDirectory;

/**
* The name of the file in case it is being stored.
*/
@ConfigItem(defaultValue = "openapi")
public String storeSchemaFileName;

/**
* Do not run the filter only at startup, but every time the document is requested (dynamic).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -929,8 +929,10 @@ Map.<String, Supplier<String>> entry("YAML", openAPI::toYAML))

smallRyeOpenApiConfig.storeSchemaDirectory.ifPresent(storageDir -> {
try {
storeGeneratedSchema(storageDir, outputTargetBuildItem, finalOpenAPI.toJSON(), "json");
storeGeneratedSchema(storageDir, outputTargetBuildItem, finalOpenAPI.toYAML(), "yaml");
storeGeneratedSchema(storageDir, smallRyeOpenApiConfig.storeSchemaFileName, outputTargetBuildItem,
finalOpenAPI.toJSON(), "json");
storeGeneratedSchema(storageDir, smallRyeOpenApiConfig.storeSchemaFileName, outputTargetBuildItem,
finalOpenAPI.toYAML(), "yaml");
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down Expand Up @@ -976,7 +978,8 @@ private void produceReflectiveHierarchy(BuildProducer<ReflectiveHierarchyBuildIt
.build());
}

private void storeGeneratedSchema(Path directory, OutputTargetBuildItem out, String schemaDocument, String format)
private void storeGeneratedSchema(Path directory, String filename, OutputTargetBuildItem out, String schemaDocument,
String format)
throws IOException {
Path outputDirectory = out.getOutputDirectory();

Expand All @@ -993,7 +996,7 @@ private void storeGeneratedSchema(Path directory, OutputTargetBuildItem out, Str
Files.createDirectories(directory);
}

Path file = directory.resolve("openapi." + format);
Path file = directory.resolve(filename + "." + format);
if (!Files.exists(file)) {
Files.createFile(file);
}
Expand Down

0 comments on commit c41dfd6

Please sign in to comment.