Skip to content

Commit

Permalink
added parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Guy Davenport committed Jun 5, 2024
1 parent d756a24 commit fe211cc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static org.brapi.schematools.core.response.Response.fail;
import static org.brapi.schematools.core.response.Response.success;
import static org.brapi.schematools.core.utils.StringUtils.toParameterCase;
import static org.brapi.schematools.core.utils.StringUtils.toSingular;

@AllArgsConstructor
public class OpenAPIGenerator {
Expand Down Expand Up @@ -99,7 +100,7 @@ private Response<OpenAPI> generate(String title, Collection<BrAPIObjectType> typ
Info info = new Info();

info.setTitle(title);
info.setVersion(metadata.getVersion());
info.setVersion(metadata.getVersion() != null ?metadata.getVersion() : "0.0.0");

openAPI.setInfo(info);

Expand Down Expand Up @@ -181,7 +182,7 @@ private Response<ApiResponse> generateSingleResponse(BrAPIObjectType type) {
new MediaType().schema(
new ObjectSchema().title(name).
addProperty("'@context'", new ObjectSchema().$ref(createSchemaRef("Context"))).
addProperty("metadata", new ObjectSchema().$ref(createSchemaRef("Metadata"))).
addProperty("metadata", new ObjectSchema().$ref(createSchemaRef("metadata"))).
addProperty("result", new ObjectSchema().$ref(createSchemaRef(type.getName()))).
addRequiredItem("metadata").
addRequiredItem("result")
Expand Down Expand Up @@ -241,18 +242,35 @@ private Response<List<Parameter>> createListGetParametersFor(BrAPIObjectType typ

List<Parameter> parameters = new ArrayList<>() ;

parameters.add(new Parameter().$ref("#/components/parameters/externalReferenceID")) ;
parameters.add(new Parameter().$ref("#/components/parameters/externalReferenceId")) ; // TODO depreciated, remove?
parameters.add(new Parameter().$ref("#/components/parameters/externalReferenceSource")) ;
parameters.add(new Parameter().$ref("#/components/parameters/page")) ;
parameters.add(new Parameter().$ref("#/components/parameters/pageSize")) ;
parameters.add(new Parameter().$ref("#/components/parameters/authorizationHeader")) ;

return requestSchema.getProperties().stream().map(this::createListGetParameter).collect(Response.toList()).
onSuccessDoWithResult(result -> parameters.addAll(0, result)).
map(() -> success(parameters)) ;

}

private Response<Parameter> createListGetParameter(BrAPIObjectProperty property) {
return createSchemaForType(property.getType()).mapResult(
schema -> new Parameter().
name(property.getName()).
name(options.getSingularForProperty(property.getName())).
in("query").
description(property.getDescription()).
required(property.isRequired()).
schema(schema)) ;
schema(upwrapSchema(schema))) ;
}

private Schema upwrapSchema(Schema schema) {
if (schema instanceof ArraySchema) {
return schema.getItems() ;
} else {
return schema ;
}
}

private Response<Operation> generatePostOperation(BrAPIObjectType type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Map;

import static org.brapi.schematools.core.utils.StringUtils.toPlural;
import static org.brapi.schematools.core.utils.StringUtils.toSingular;


@Getter
Expand Down Expand Up @@ -200,4 +201,9 @@ public String getSearchRequestNameFor(String name) {
public String getPluralFor(String name) {
return toPlural(name) ;
}

@JsonIgnore
public String getSingularForProperty(String name) {
return toSingular(name) ;
}
}

0 comments on commit fe211cc

Please sign in to comment.