Skip to content

Commit

Permalink
Adding support for FIWARE Headers on FIWARE Models
Browse files Browse the repository at this point in the history
  • Loading branch information
computate committed Dec 1, 2023
1 parent 92d57e0 commit 4aed5c7
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 33 deletions.
72 changes: 72 additions & 0 deletions src/gen/java/org/computate/vertx/writer/ApiWriterGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,63 @@ public static String staticSearchFqClassIsBase(ComputateSiteRequest siteRequest_
return ApiWriter.staticSearchStrClassIsBase(siteRequest_, ApiWriter.staticSearchClassIsBase(siteRequest_, ApiWriter.staticSetClassIsBase(siteRequest_, o)));
}

/////////////////
// classFiware //
/////////////////


/** The entity classFiware
* is defined as null before being initialized.
*/
@JsonProperty
@JsonInclude(Include.NON_NULL)
protected Boolean classFiware;

/** <br> The entity classFiware
* is defined as null before being initialized.
* <br><a href="https://solr-solr.apps-crc.testing/solr/computate/select?q=*:*&fq=partEstEntite_indexed_boolean:true&fq=classeNomCanonique_enUS_indexed_string:org.computate.vertx.writer.ApiWriter&fq=entiteVar_enUS_indexed_string:classFiware">Find the entity classFiware in Solr</a>
* <br>
* @param c is for wrapping a value to assign to this entity during initialization.
**/
protected abstract void _classFiware(Wrap<Boolean> c);

public Boolean getClassFiware() {
return classFiware;
}

public void setClassFiware(Boolean classFiware) {
this.classFiware = classFiware;
}
@JsonIgnore
public void setClassFiware(String o) {
this.classFiware = ApiWriter.staticSetClassFiware(siteRequest_, o);
}
public static Boolean staticSetClassFiware(ComputateSiteRequest siteRequest_, String o) {
return Boolean.parseBoolean(o);
}
protected ApiWriter classFiwareInit() {
Wrap<Boolean> classFiwareWrap = new Wrap<Boolean>().var("classFiware");
if(classFiware == null) {
_classFiware(classFiwareWrap);
Optional.ofNullable(classFiwareWrap.getO()).ifPresent(o -> {
setClassFiware(o);
});
}
return (ApiWriter)this;
}

public static Boolean staticSearchClassFiware(ComputateSiteRequest siteRequest_, Boolean o) {
return o;
}

public static String staticSearchStrClassFiware(ComputateSiteRequest siteRequest_, Boolean o) {
return o == null ? null : o.toString();
}

public static String staticSearchFqClassFiware(ComputateSiteRequest siteRequest_, String o) {
return ApiWriter.staticSearchStrClassFiware(siteRequest_, ApiWriter.staticSearchClassFiware(siteRequest_, ApiWriter.staticSetClassFiware(siteRequest_, o)));
}

/////////////////////
// classSimpleName //
/////////////////////
Expand Down Expand Up @@ -2867,6 +2924,7 @@ public void initApiWriter() {
classApiTagInit();
classExtendsBaseInit();
classIsBaseInit();
classFiwareInit();
classSimpleNameInit();
appNameInit();
classAbsolutePathInit();
Expand Down Expand Up @@ -3003,6 +3061,8 @@ public Object obtainApiWriter(String var) {
return oApiWriter.classExtendsBase;
case "classIsBase":
return oApiWriter.classIsBase;
case "classFiware":
return oApiWriter.classFiware;
case "classSimpleName":
return oApiWriter.classSimpleName;
case "appName":
Expand Down Expand Up @@ -3112,6 +3172,8 @@ public static Object staticSetApiWriter(String entityVar, ComputateSiteRequest s
return ApiWriter.staticSetClassExtendsBase(siteRequest_, o);
case "classIsBase":
return ApiWriter.staticSetClassIsBase(siteRequest_, o);
case "classFiware":
return ApiWriter.staticSetClassFiware(siteRequest_, o);
case "classSimpleName":
return ApiWriter.staticSetClassSimpleName(siteRequest_, o);
case "appName":
Expand Down Expand Up @@ -3198,6 +3260,8 @@ public static Object staticSearchApiWriter(String entityVar, ComputateSiteReques
return ApiWriter.staticSearchClassExtendsBase(siteRequest_, (Boolean)o);
case "classIsBase":
return ApiWriter.staticSearchClassIsBase(siteRequest_, (Boolean)o);
case "classFiware":
return ApiWriter.staticSearchClassFiware(siteRequest_, (Boolean)o);
case "classSimpleName":
return ApiWriter.staticSearchClassSimpleName(siteRequest_, (String)o);
case "appName":
Expand Down Expand Up @@ -3284,6 +3348,8 @@ public static String staticSearchStrApiWriter(String entityVar, ComputateSiteReq
return ApiWriter.staticSearchStrClassExtendsBase(siteRequest_, (Boolean)o);
case "classIsBase":
return ApiWriter.staticSearchStrClassIsBase(siteRequest_, (Boolean)o);
case "classFiware":
return ApiWriter.staticSearchStrClassFiware(siteRequest_, (Boolean)o);
case "classSimpleName":
return ApiWriter.staticSearchStrClassSimpleName(siteRequest_, (String)o);
case "appName":
Expand Down Expand Up @@ -3370,6 +3436,8 @@ public static String staticSearchFqApiWriter(String entityVar, ComputateSiteRequ
return ApiWriter.staticSearchFqClassExtendsBase(siteRequest_, o);
case "classIsBase":
return ApiWriter.staticSearchFqClassIsBase(siteRequest_, o);
case "classFiware":
return ApiWriter.staticSearchFqClassFiware(siteRequest_, o);
case "classSimpleName":
return ApiWriter.staticSearchFqClassSimpleName(siteRequest_, o);
case "appName":
Expand Down Expand Up @@ -3460,6 +3528,7 @@ public static String staticSearchFqApiWriter(String entityVar, ComputateSiteRequ
public static final String VAR_classApiTag = "classApiTag";
public static final String VAR_classExtendsBase = "classExtendsBase";
public static final String VAR_classIsBase = "classIsBase";
public static final String VAR_classFiware = "classFiware";
public static final String VAR_classSimpleName = "classSimpleName";
public static final String VAR_appName = "appName";
public static final String VAR_classAbsolutePath = "classAbsolutePath";
Expand Down Expand Up @@ -3512,6 +3581,7 @@ public static String staticSearchFqApiWriter(String entityVar, ComputateSiteRequ
public static final String DISPLAY_NAME_classApiTag = "";
public static final String DISPLAY_NAME_classExtendsBase = "";
public static final String DISPLAY_NAME_classIsBase = "";
public static final String DISPLAY_NAME_classFiware = "";
public static final String DISPLAY_NAME_classSimpleName = "";
public static final String DISPLAY_NAME_appName = "";
public static final String DISPLAY_NAME_classAbsolutePath = "";
Expand Down Expand Up @@ -3595,6 +3665,8 @@ public static String displayNameApiWriter(String var) {
return DISPLAY_NAME_classExtendsBase;
case VAR_classIsBase:
return DISPLAY_NAME_classIsBase;
case VAR_classFiware:
return DISPLAY_NAME_classFiware;
case VAR_classSimpleName:
return DISPLAY_NAME_classSimpleName;
case VAR_appName:
Expand Down
72 changes: 39 additions & 33 deletions src/main/java/org/computate/vertx/openapi/Swagger2Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,39 +75,6 @@ public Future<Void> writeApi() {
JsonObject authClients = Optional.ofNullable(config.getValue(ComputateConfigKeys.AUTH_CLIENTS)).map(v -> v instanceof JsonObject ? (JsonObject)v : new JsonObject(v.toString())).orElse(new JsonObject());

wPaths.tl(0, "paths:");
authClients.fieldNames().forEach(authClientOpenApiId -> {
JsonObject authClient = authClients.getJsonObject(authClientOpenApiId);
String authCallbackUri = authClient.getString(ComputateConfigKeys.AUTH_CALLBACK_URI);
String authLogoutUri = authClient.getString(ComputateConfigKeys.AUTH_LOGOUT_URI);

wPaths.l();
wPaths.tl(1, authCallbackUri, ":");
wPaths.tl(2, "get:");
wPaths.tl(3, "operationId: callback");
wPaths.tl(3, "x-vertx-event-bus: ", appName, "-", languageName, "-", authClientOpenApiId, "-callback");
wPaths.tl(3, "description: >+");
wPaths.tl(3, "responses:");
wPaths.tl(4, "'200':");
wPaths.tl(5, "description: >+");
wPaths.tl(5, "content:");
wPaths.tl(6, "application/json; charset=utf-8:");
wPaths.tl(7, "schema:");
wPaths.tl(8, "type: string");
wPaths.l();
wPaths.tl(1, authLogoutUri, ":");
wPaths.tl(2, "get:");
wPaths.tl(3, "operationId: logout");
wPaths.tl(3, "x-vertx-event-bus: ", appName, "-", languageName, "-", authClientOpenApiId, "-logout");
wPaths.tl(3, "description: >+");
wPaths.tl(3, "responses:");
wPaths.tl(4, "'200':");
wPaths.tl(5, "description: >+");
wPaths.tl(5, "content:");
wPaths.tl(6, "application/json; charset=utf-8:");
wPaths.tl(7, "schema:");
wPaths.tl(8, "type: string");
wPaths.l();
});

if(openApiVersionNumber == 2) {
wSchemas.tl(0, "definitions:");
Expand All @@ -129,6 +96,45 @@ public Future<Void> writeApi() {
}

loadClasses().onSuccess(classDoc -> {
authClients.fieldNames().forEach(authClientOpenApiId -> {
JsonObject authClient = authClients.getJsonObject(authClientOpenApiId);
String authCallbackUri = authClient.getString(ComputateConfigKeys.AUTH_CALLBACK_URI);
String authLogoutUri = authClient.getString(ComputateConfigKeys.AUTH_LOGOUT_URI);

wPaths.l();
wPaths.tl(1, authLogoutUri, ":");
wPaths.tl(2, "get:");
wPaths.tl(3, "operationId: logout");
wPaths.tl(3, "x-vertx-event-bus: ", appName, "-", languageName, "-", authClientOpenApiId, "-logout");
wPaths.tl(3, "description: >+");
wPaths.tl(3, "responses:");
wPaths.tl(4, "'200':");
wPaths.tl(5, "description: >+");
wPaths.tl(5, "content:");
wPaths.tl(6, "application/json; charset=utf-8:");
wPaths.tl(7, "schema:");
wPaths.tl(8, "type: string");
});
authClients.fieldNames().forEach(authClientOpenApiId -> {
JsonObject authClient = authClients.getJsonObject(authClientOpenApiId);
String authCallbackUri = authClient.getString(ComputateConfigKeys.AUTH_CALLBACK_URI);
String authLogoutUri = authClient.getString(ComputateConfigKeys.AUTH_LOGOUT_URI);

wPaths.l();
wPaths.tl(1, authCallbackUri, ":");
wPaths.tl(2, "get:");
wPaths.tl(3, "operationId: callback");
wPaths.tl(3, "x-vertx-event-bus: ", appName, "-", languageName, "-", authClientOpenApiId, "-callback");
wPaths.tl(3, "description: >+");
wPaths.tl(3, "responses:");
wPaths.tl(4, "'200':");
wPaths.tl(5, "description: >+");
wPaths.tl(5, "content:");
wPaths.tl(6, "application/json; charset=utf-8:");
wPaths.tl(7, "schema:");
wPaths.tl(8, "type: string");
});

LOG.info("Write OpenAPI completed. ");
promise.complete();
}).onFailure(ex -> {
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/org/computate/vertx/writer/ApiWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ protected void _classIsBase(Wrap<Boolean> c) {
c.o((Boolean)classSolrDocument.get("classeEstBase_stored_boolean"));
}

protected void _classFiware(Wrap<Boolean> c) {
c.o((Boolean)classSolrDocument.get("classeFiware_stored_boolean"));
}

protected void _classSimpleName(Wrap<String> c) {
c.o((String)classSolrDocument.get("classeNomSimple_enUS_stored_string"));
}
Expand Down Expand Up @@ -509,6 +513,24 @@ public void writeApi(Boolean id) throws Exception, Exception {
wPaths.tl(3, "produces:");
wPaths.tl(4, "- ", classApiMediaType200Method);
}
if(!id && classFiware) {
wRequestHeaders.tl(4, "- name: Fiware-Service");
wRequestHeaders.tl(5, "in: header");
wRequestHeaders.tl(5, "schema:");
wRequestHeaders.tl(6, "type: string");
wRequestHeaders.tl(4, "- name: Fiware-ServicePath");
wRequestHeaders.tl(5, "in: header");
wRequestHeaders.tl(5, "schema:");
wRequestHeaders.tl(6, "type: string");
wRequestHeaders.tl(4, "- name: NGSILD-Tenant");
wRequestHeaders.tl(5, "in: header");
wRequestHeaders.tl(5, "schema:");
wRequestHeaders.tl(6, "type: string");
wRequestHeaders.tl(4, "- name: NGSILD-Path");
wRequestHeaders.tl(5, "in: header");
wRequestHeaders.tl(5, "schema:");
wRequestHeaders.tl(6, "type: string");
}

if(!wRequestHeaders.getEmpty() || "GET".equals(classApiMethodMethod) || "DELETE".equals(classApiMethodMethod) || "PUT".equals(classApiMethodMethod) || "PATCH".equals(classApiMethodMethod)) {
wPaths.tl(3, "parameters:");
Expand Down

0 comments on commit 4aed5c7

Please sign in to comment.