Skip to content

Commit

Permalink
add: custom query
Browse files Browse the repository at this point in the history
  • Loading branch information
mosoriob committed Dec 11, 2019
1 parent 0b67edc commit 9c04441
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 37 deletions.
56 changes: 28 additions & 28 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,31 @@ firebase:
key:


custom_queries:
/custom/configurationsetups:
get:
description: Gets a list of all ConfigurationSetup entities
parameters:
- description: Username to query
in: query
name: username
required: false
schema:
type: string
- description: Filter by label
in: query
name: label
required: false
schema:
type: string
responses:
200:
content:
application/json:
schema:
items:
$ref: '#/components/schemas/ConfigurationSetup'
type: array
description: Successful response - returns an array of ConfigurationSetup
entities.
summary: List all ConfigurationSetup entities
custom_paths:
/custom/configurationsetups:
get:
description: Gets a list of all ConfigurationSetup entities
parameters:
- description: Username to query
in: query
name: username
required: false
schema:
type: string
- description: Filter by label
in: query
name: label
required: false
schema:
type: string
responses:
'200':
content:
application/json:
schema:
items:
$ref: '#/components/schemas/ConfigurationSetup'
type: array
description: Successful response - returns an array of ConfigurationSetup
entities.
summary: List all ConfigurationSetup entities
16 changes: 8 additions & 8 deletions src/main/java/edu/isi/oba/Oba.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import edu.isi.oba.config.RelationConfig;
import edu.isi.oba.config.YamlConfig;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.PathItem;
import io.swagger.v3.parser.OpenAPIV3Parser;
import org.apache.commons.io.FileUtils;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
Expand All @@ -13,15 +14,11 @@
import java.io.*;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

import org.apache.commons.cli.*;

class Oba {

public static void main(String[] args) throws Exception {
final String base_project_dir = "./tools/base_project/";

Expand All @@ -34,11 +31,14 @@ public static void main(String[] args) throws Exception {
python_copy_base_project(base_project_dir, destination_dir);
//read ontologies and get schema and paths
List<Mapper> mappers = get_mappers(config_data);
//obtain custom paths
LinkedHashMap<String, PathItem> custom_paths = config_data.getCustom_paths();

//get base of openapi
OpenAPI openapi_base = new OpenAPIV3Parser().read(config_data.getOpenapi_base());
//obtain the output directory to write the openapi specification
//write the openapi specification
generate_openapi_spec(openapi_base, mappers, destination_dir);
generate_openapi_spec(openapi_base, mappers, destination_dir, custom_paths);
}

/**
Expand Down Expand Up @@ -73,10 +73,10 @@ private static void python_copy_base_project(String base_project_dir, String des
FileUtils.copyDirectory(baseProject.toFile(), destinationProject.toFile());
}

private static void generate_openapi_spec(OpenAPI openapi_base, List<Mapper> mappers, String dir) throws IOException {
private static void generate_openapi_spec(OpenAPI openapi_base, List<Mapper> mappers, String dir, LinkedHashMap<String, PathItem> custom_paths) throws IOException {
String destinationProjectDirectory = dir;
Path destinationProject = Paths.get(destinationProjectDirectory);
Serializer serializer = new Serializer(mappers, destinationProject, openapi_base);
Serializer serializer = new Serializer(mappers, destinationProject, openapi_base, custom_paths);
SerializerPython serializer_python = new SerializerPython(mappers, destinationProject, openapi_base);
}

Expand Down
8 changes: 7 additions & 1 deletion src/main/java/edu/isi/oba/Serializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

class Serializer {
//TODO: validate the yaml
public Serializer(List<Mapper> mappers, java.nio.file.Path dir, OpenAPI openAPI) throws IOException {
public Serializer(List<Mapper> mappers, java.nio.file.Path dir, OpenAPI openAPI, LinkedHashMap<String, PathItem> custom_paths) throws IOException {
Map<String, Object> extensions = new HashMap<String, Object>();
final String openapi_file = "openapi.yaml";

Expand All @@ -37,6 +37,12 @@ public Serializer(List<Mapper> mappers, java.nio.file.Path dir, OpenAPI openAPI
components.securitySchemes(securitySchemes);
}

//add custom paths
custom_paths.forEach((k, v) -> {
System.out.println("inserting custom query " + k);
paths.addPathItem(k, v);
});

openAPI.setPaths(paths);
openAPI.components(components);

Expand Down
15 changes: 15 additions & 0 deletions src/main/java/edu/isi/oba/config/YamlConfig.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package edu.isi.oba.config;


import io.swagger.v3.oas.models.PathItem;
import io.swagger.v3.oas.models.Paths;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -17,6 +21,8 @@ public class YamlConfig {
public EndpointConfig endpoint;
public FirebaseConfig firebase;
public Map<String, List<RelationConfig>> relations;
private LinkedHashMap<String, PathItem> custom_paths = null;


public String getOutput_dir() {
return output_dir;
Expand Down Expand Up @@ -81,5 +87,14 @@ public Map<String, List<RelationConfig>> getRelations() {
public void setRelations(Map<String, List<RelationConfig>> relations) {
this.relations = relations;
}


public LinkedHashMap<String, PathItem> getCustom_paths() {
return custom_paths;
}

public void setCustom_paths(LinkedHashMap<String, PathItem> custom_paths) {
this.custom_paths = custom_paths;
}
}

0 comments on commit 9c04441

Please sign in to comment.