using 4.3.1 of open api generator and trying to get the java code out of the json.
In the json file I have the following (changed for example):
"xComponents": {
"type": "array",
"title": "This is a title",
"items": {
"oneOf": [
{
"$ref": "xComponent.AAA.schema.json"
},
{
"$ref": "xComponent.BBB.schema.json"
},
{
"$ref": "xComponent.CCC.schema.json"
},
{
"$ref": "xComponent.DDD.schema.json"
}
],
"type": "object"
},
"minItems": 1
}
It generates this list wierd class name that cannot get build:
private List<**OneOfxComponentAAASchemaJsonxComponentBBBSchemaJsonxComponentCCCSchemaJsonxComponentDDDSchemaJson**> xComponents =
new ArrayList<**OneOfxComponentAAASchemaJsonxComponentBBBSchemaJsonxComponentCCCSchemaJsonxComponentDDDSchemaJson**>();
Whats the correct way to deal with oneOf? what im I doing wrong (either with the json file or with the open api generator)?
Related
We have implemented swagger using OpenAPI 3.
We have a requirement where the external request will be sent with a path "{host}/v1/names" which will then be interpreted at gateway level and forwarded as "{host}/api/v1/names" to the deployed springboot application
In the springboot application we are using rest controller with
#RequestMapping(value="/api/v1/names")
So, when OpenApi Json is generated to be used in swagger, it defines path as "/api/v1/names". However, since external customer would use "/v1/names" to access the API, we want to show "/v1/names" in swagger and OpenApi json
Current JSON looks like this:
{
"openapi": "3.0.1",
"info": {
"title": "External API",
"description": "This set of API is used to serve external clients",
"version": "0.1"
},
"servers": [
{
"url": "https://api.xyz.net/",
"description": "Live"
}
],
"paths": {
"/api/v1/names": {
"get": {
"summary": ".",
"operationId": "getNames",
"parameters": [
{
"name": "pageable",
"in": "query",
"required": true,
"schema": {
"$ref": "#/components/schemas/Pageable"
}
}
],
"responses": {
"200": {
"description": "List of names",
"content": {
"*/*": {
"schema": {
"$ref": "#/components/schemas/Pageable response"
}
}
}
}
}
}
}
}
}
Expected JSON (Different "path" value):
{
"openapi": "3.0.1",
"info": {
"title": "External API",
"description": "This set of API is used to serve external clients",
"version": "0.1"
},
"servers": [
{
"url": "https://api.xyz.net/",
"description": "Live"
}
],
"paths": {
"/v1/names": {
"get": {
"summary": ".",
"operationId": "getNames",
"parameters": [
{
"name": "pageable",
"in": "query",
"required": true,
"schema": {
"$ref": "#/components/schemas/Pageable"
}
}
],
"responses": {
"200": {
"description": "List of names",
"content": {
"*/*": {
"schema": {
"$ref": "#/components/schemas/Pageable response"
}
}
}
}
}
}
}
}
}
I have been trying to figure out any way to do this through some configuration or annotation, but not found anything yet.
Thanks in advance for your suggestions and help.
I'm constructing a message to be sent through my spring boot application.
I was testing out the templates and I have created one where most of the elements are static except a link that needs to be generated by the code and added to the Json.
Currently the Json message looks like this:
{
"blocks": [
{
"type": "context",
"elements": [
{
"type": "image",
"image_url": "https://api.slack.com/img/blocks/bkb_template_images/highpriority.png",
"alt_text": "High Priority"
},
{
"type": "mrkdwn",
"text": "*High Priority*"
}
]
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Hercules Platform Status Response failed Messages*"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Please click the link to download the file*"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*<LINK|SOME_LINK>*"
}
}
]
}
I'm not sure how to construct this Json in my spring boot application. Since most of it is static, should I just load this template as a string and append the last link section?
I'm not able to figure out the slack classes in java to build such a message.
I'm building a custom generator to generate TypeScript/Angular models for an angular application. For a starting point, I copied the code from https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java
I'm trying to figure out how to prevent the generator from generating "AllOf" and from extending models from "AllOf" models.
The generator already generates a model with everything it needs without needing to extend from *AllOf.
I've been able to modify the .java file to prevent it from importing classes that with with "AllOf", but I can't find any documentation or examples to restrict extending from classes that end with "AllOf"
Am I missing something? It seems like there should be a way to tell the generator to just not import or create "AllOf" classes.
// what I get:
import { ValidatePassword } from './validate-password.model';
export interface ChangePassword extends ChangePasswordAllOf, ValidatePassword {
...
}
// what I want
import { ValidatePasswordModel } from './validate-password.model';
export interface ChangePassword extends ValidatePassword {
...
}
Here's my modelGeneric.mustache template:
export interface {{classname}}{{#allOf}}{{#-first}} extends {{/-first}}{{{.}}}{{^-last}}, {{/-last}}{{/allOf}} { {{>modelGenericAdditionalProperties}}
{{#vars}}
{{#description}}
/**
* {{{.}}}
*/
{{/description}}
{{#isReadOnly}}readonly {{/isReadOnly}}{{{name}}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}};
{{/vars}}
}{{>modelGenericEnums}}
Here's the relevant schema sample:
...
"ChangePassword": {
"allOf": [
{
"$ref": "#/components/schemas/ValidatePassword"
},
{
"type": "object",
"additionalProperties": false,
"required": [
"OldPassword"
],
"properties": {
"OldPassword": {
"title": "Current password",
"type": "string",
"minLength": 1
}
}
}
]
},
...
According to this: https://github.com/OpenAPITools/openapi-generator/issues/3100
Could you try:
"ChangePassword": {
"type": "object",
"additionalProperties": false,
"required": [
"OldPassword"
],
"properties": {
"OldPassword": {
"title": "Current password",
"type": "string",
"minLength": 1
}
},
"allOf": [{
"$ref": "#/components/schemas/ValidatePassword"
}]
}
I have a complex index with a ngram analyzer. I want to be able to create a new index through the Java API. I am currently using Kotlin for this but using the same framework. I have created the schema for this index as so:
{
"settings": {
"index": {
"max_ngram_diff": 20,
"search.idle.after": "10m"
},
"analysis": {
"analyzer": {
"ngram3_analyzer": {
"tokenizer": "ngram3_tokenizer",
"filter": [
"lowercase"
]
}
},
"tokenizer": {
"ngram3_tokenizer": {
"type": "ngram",
"min_gram": 3,
"max_gram": 20
}
}
}
},
"mappings": {
"dynamic": "strict",
"_doc": {
"properties": {
"name": {
"type": "keyword",
"fields": {
"partial": {
"type": "text",
"analyzer": "ngram3_analyzer",
"search_analyzer": "keyword"
},
"text": {
"type": "text"
}
}
},
"location": {
"type": "geo_shape",
"ignore_malformed": true
},
"type": {
"type": "keyword"
},
"sort": {
"type": "integer"
}
}
}
}
}
This json schema works when manually passing it via a rest client PUT call.
{
"acknowledged": true,
"shards_acknowledged": true,
"index": "new_index_created"
}
Passing the same schema via elastic java API using the following koltin function:
private fun createIndex(index: String, schema: String) {
val createIndexRequest = CreateIndexRequest(index).mapping(schema, XContentType.JSON)
getClient().indices().create(createIndexRequest, RequestOptions.DEFAULT)
}
I get this response:
Elasticsearch exception [type=mapper_parsing_exception, reason=Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters: [settings : {index={max_ngram_diff=20, search.idle.after=10m}, analysis={analyzer={ngram3_analyzer={filter=[lowercase], tokenizer=ngram3_tokenizer}}, tokenizer={ngram3_tokenizer={min_gram=3, type=ngram, max_gram=20}}}}] [mappings : {_doc={properties={name={type=keyword, fields={text={type=text}, partial={search_analyzer=keyword, analyzer=ngram3_analyzer, type=text}}}, location={ignore_malformed=true, type=geo_shape}, sort={type=integer}, type={type=keyword}}}, dynamic=strict}]]
any help on this issue would be great :)
The error you get is because you're passing both mappings and settings into the mapping(...) call.
You can either call mapping() with only the mappings section and setting() with the settings section, or you can call source() like this:
val createIndexRequest = CreateIndexRequest(index).source(schema, XContentType.JSON)
^
|
change this
I am very new to hapi FHIR, I am trying to encode the request in following format.
CoverageEligibilityRequest coverageEligibilityRequest = new CoverageEligibilityRequest();
Patient patient = new Patient().addIdentifier(new Identifier().setType(getPatientIdentifierCodeableConcept()).setSystem("http://www.abc.xyz").setValue("123"));
coverageEligibilityRequest.setPatient(new Reference(patient));
Above code is java snippet for populating the patient in CoverageEligibilityRequest.
{
"resourceType": "Bundle",
"type": "batch",
"entry": [ {
"resource": {
"resourceType": "CoverageEligibilityRequest",
"id": "7890",
"contained": [ {
"resourceType": "Patient",
"id": "1",
"identifier": [ {
"type": {
"coding": [ {
...
...
}
But I want the request should be of following format
{
"resourceType": "Bundle",
"type": "batch",
"entry": [ {
"resource": {
"resourceType": "CoverageEligibilityRequest",
"id": "7890",
"patient": {
"type": "Patient",
"identifier": {
"type": {
"coding": [ {
...
...
} ]
},
where I want to omit contained with actual string?
FHIR doesn't generally let you express an entire graph of objects as a single resource, so if you're trying to send a Patient resource as part of a CoverageEligibilityRequest resource, the only way you can do that is by setting the patient in the contained field. The CoverageEligibilityResource.patient field is defined as a Reference type and so can only contain the data allowed by a Reference data type and not arbitrary data.
It seems like what you actually want to do is to add a Patient to the HAPI FHIR server and a CoverageEligibilityRequest resource that references the patient. The right way to do this in FHIR is to construct a single batch or transaction bundle containing both of the resources. Basically, you want to construct a Bundle that looks something like this:
{
"resourceType": "Bundle",
"type": "batch",
"entry": [ {
"resource": {
"resourceType": "Patient",
"id": "1",
"identifier": [ {
"type": {
"coding": [ {
...
}
}, {
"resource": {
"resourceType": "CoverageEligibilityRequest",
"id": "7890",
"patient": "Patient/1",
...
The easiest way to construct something similar in HAPI FHIR would be to use a transaction bundle like this:
IGenericClient client = ...
CoverageEligibilityRequest coverageEligibilityRequest = new CoverageEligibilityRequest();
Patient patient = new Patient().addIdentifier(new Identifier().setType(getPatientIdentifierCodeableConcept()).setSystem("http://www.abc.xyz").setValue("123"));
coverageEligibilityRequest.setPatient(new Reference(patient));
client.transaction().withResources(patient, coverageEligibilityRequest);