Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for adding Markdown descriptions to models in OpenAPI spec #515

Draft
wants to merge 1 commit into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`.

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