Skip to content

Commit

Permalink
Add support for adding Markdown descriptions to models in OpenAPI spec
Browse files Browse the repository at this point in the history
  • Loading branch information
arteymix committed Dec 13, 2022
1 parent 960588f commit bee6291
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ protected List<String> resolveAllowableValues( Annotated a, Annotation[] annotat
protected String resolveDescription( Annotated a, Annotation[] annotations, io.swagger.v3.oas.annotations.media.Schema schema ) {
String description = super.resolveDescription( a, annotations, schema );

// lookup classpath (fallback)
if ( description == null ) {
description = resolveDescriptionFromClassPath( a );
}

// append available properties to the description
if ( FilterArg.class.isAssignableFrom( a.getRawType() ) && getGemmaExtensionProperty( schema, "filteringService" ) != null ) {
String availableProperties = resolveAvailableProperties( schema );
Expand All @@ -118,6 +123,23 @@ private String resolveAvailableProperties( io.swagger.v3.oas.annotations.media.S
filteringService.getFilterableProperties().stream().map( p -> String.format( "- %s %s", p, filteringService.getFilterablePropertyType( p ).getSimpleName() ) ).collect( Collectors.joining( "\n" ) ) );
}

private String resolveDescriptionFromClassPath( Annotated a ) {
if ( descriptionsCache.containsKey( a.getName() ) ) {
return descriptionsCache.get( a.getName() );
}
ClassPathResource cpr = new ClassPathResource( "restapidocs/models/" + a.getName() + ".md" );
if ( cpr.exists() ) {
try ( InputStream in = cpr.getInputStream() ) {
String description = StreamUtils.copyToString( in, StandardCharsets.UTF_8 );
descriptionsCache.put( a.getName(), description );
return description;
} catch ( IOException e ) {
throw new RuntimeException( e );
}
}
return null;
}

/**
* Retrieve the value of an OpenAPI Gemma extension property.
* <p>
Expand Down
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# FilterArg

## Syntax

The filter use a predictate structured in conjunctive normal form (CNF).

Platforms can be filtered by taxon using the `taxon`.

- ``
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This argument limits the number of results.

0 comments on commit bee6291

Please sign in to comment.