I'm trying to create API resources containing External file reference in parameters and responses and try to get these references resolved using swagger. (Support importing OpenAPI definitions with external references).
For that, I am getting the YAML files as file archive and there will be a master main.YAML file and from that other files are referenced.
OpenAPIV3Parser openAPIV3Parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setFlatten(true);
OpenAPI openAPI = openAPIV3Parser.read(extractedLocation + "/main.yaml", null, options);
String openAPIContent = Yaml.mapper().writerWithDefaultPrettyPrinter().writeValueAsString(openAPI);
APIDefinitionValidationResponse apiDefinitionValidationResponse = new APIDefinitionValidationResponse ();
apiDefinitionValidationResponse = OASParserUtil.validateAPIDefinition(openAPIContent, returnContent);
I tried with this code snippet but the apiDefinitionValidationResponse is throwing an error when there is $ref in the YAML file. If there's no $ref then apiDefinitionValidationResponse is a success and api is created.
So i doubt there is a problem in giving the data to OASParserUtil.validateAPIDefinition method (validateAPIDefinition method has no issues and it has been validated and tested)
Could someone help me with this?
The generated YAML file has extensions{} lines all over it
Error messages in debug logs:
attribute info.license.extensions is unexpected
attribute info.extensions is unexpected
attribute components.schemas.ErrorListItem.extensions is unexpected
attribute components.schemas.MenuItem.extensions is unexpected
attribute components.schemas.Order.extensions is unexpected
What i can tell from the error message and your result yaml is, that the transformation step adds some extensions: {} lines into the final yaml.
Having an extensions attribute at those places it complains about is not allowed by the OpenAPI specification.
Looks like your yaml serialization is to simple. Looking at the SerializerUtils from the openapi-generator they have a bit more configuration.
The extra module takes care of serializing only the interesting part of the OpenAPI object.
Related
I am using attlasian library for schema validation of swagger.
com.atlassian.oai.validator.restassured.OpenApiValidationFilter
private static final OpenApiValidationFilter SWAGGER_FILTER_ = new OpenApiValidationFilter( OpenApiInteractionValidator.createFor("swagger.yml") .withBasePathOverride("ApiBasePath") .build());
The above code works only when the swagger specs are available in src/main/api folder.
I am trying to read specs from src/main/swagger or src/main/api/swaggers folder.
" java.lang.RuntimeException: Could not find /api/swaggers/swagger.yml
on the classpath"
What am I missing here ?
You can use real path, instead of Object
OpenApiValidationFilter validationFilter = new OpenApiValidationFilter(
OpenApiInteractionValidator.createFor(Paths.get(System.getProperty("user.dir"), "src", "main", "swagger", "swagger.yml").toString()
).build());
I am working with the Tika Java library. I'm using Lucee (a sub part of ColdFusion) and when I use an online example to retrieve text from a PDF I get an empty string.
What is the setup?
I've installed Lucee locally and have access to an empty index.cfm page. I've added the Tika jar file to the project and I see it's loaded correctly in the Lucee admin.
What is the code?
The following part is the most simple code I could find to convert a PDF to text:
handler = createObject("java", "org.apache.tika.sax.BodyContentHandler");
metadata = createObject("java", "org.apache.tika.metadata.Metadata");
inputstream = createObject("java", "java.io.FileInputStream").init(createObject("java", "java.io.File").init('C:\lucee\tomcat\webapps\ROOT\test\dummy.pdf'));
pcontext = createObject("java", "org.apache.tika.parser.ParseContext");
pdfparser = createObject("java", "org.apache.tika.parser.AutoDetectParser");
pdfparser.parse(inputstream, handler, metadata, pcontext);
writeDump(handler.toString());
so when I run this I get an empty string and I expect the text inside the PDF. Also all the metadata is empty.
Conclusion
I think that the library is perhaps not loaded correctly. But what can I do to see where this is going wrong? I don't get any error, just empty values. Tried different PDFs and even different files. Tried the autoparser and different kind of codes. Is this maybe a Lucee problem? Or a Java problem?
I have a microservice running which reads handlebar from yml file. Right now I am working on partials where some part of my every template can be made common/re-used. Since I am reading handlebar template name from my yml file. It is one template name at a time. But how can I include/import/compile partial in Java.
Currently I am getting an error:
Partial xxx.hbs could not be found at xxx.hbs
Tried this solution:
TemplateLoader loader = new ClassPathTemplateLoader("/resources",
".hbs");
Handlebars handlebars = new Handlebars(loader);
Template template = handlebars.compile("greeting");
But I want to load a partial let say which is inside greeting.hbs.
Partial xxx.hbs could not be found at xxx.hbs
I'm using the Google Drive API for Java (v3-rev111-1.23). I'm trying to remove a property from a resource.
I followed this documentation:
https://developers.google.com/drive/v3/reference/files/update
https://developers.google.com/drive/v3/web/migration#methods
This is the code I wrote:
Drive service = getDriveService();
File file = new File();
Map<String,String> properties = new HashMap<>();
properties.put("propA", null);
file.setProperties(properties);
file = service.files().update(fileId, file).execute();
The problem is that the property is never cleared. Remains with the previous value.
If I write the generated json with:
System.out.println(service.files().update(fileId, file).getJsonContent());
I get:
{properties={propA=null}}
Using the same code to add a new property like:
properties.put("test", "yes");
I get:
{properties={test=yes}}
and it works properly.
Has someone faced and solved this problem?
I read this post Google Drive Java API V3 delete custom property from 2016, but no solution was given.
More details:
Using the try-its of the web (https://developers.google.com/drive/v3/reference/files/update) I could create properties, modify them and even delete them.
Thanks.
Here's what I can share that might help you, using the Try-its:
I created a file using Files.create and created a custom property
appProperties{
"supersaiyan": "yes"
}
Then I deleted it using Files.update:
appProperties{
"supersaiyan": null
}
When I tried to fetch the appProperties, I got {} which means successfully deleted.
I am using the apache commons configuration library to read a configuration xml and it works nicely. However, I am not able to modify the value of the elements or add new ones.
To read the xml I use the following code:
XMLConfiguration config = new XMLConfiguration(dnsXmlPath);
boolean enabled = config.getBoolean("enabled", true));
int size = config.getInt("size");
To write I am trying to use:
config.setProperty("newProperty", "valueNewProperty");
config.save();
If I call config.getString("newProperty"), I obtain "valueNewProperty", but the xml has not been changed.
Obviously it is not the right way or I am missing something, because it does not work.
Could anybody tell me how to do this?
Thanks in advance.
You're modifying xml structure in memory
The parsed document will be stored keeping its structure. The class also tries to preserve as much information from the loaded XML document as possible, including comments and processing instructions. These will be contained in documents created by the save() methods, too.
Like other file based configuration classes this class maintains the name and path to the loaded configuration file. These properties can be altered using several setter methods, but they are not modified by save() and load() methods. If XML documents contain relative paths to other documents (e.g. to a DTD), these references are resolved based on the path set for this configuration.
You need to use XMLConfiguration.html#save(java.io.Writer) method
For example, after you've done all your modifications save it:
config.save(new PrintWriter(new File(dnsXmlPath)));
EDIT
As mentioned in comment, calling config.load() before calling setProperty() method fixes the issue.
I solved it with the following lines. I was missing the config.load().
XMLConfiguration config = new XMLConfiguration(dnsXmlPath);
config.load();
config.setProperty("newProperty", "valueNewProperty");
config.save();
It is true though that you can used the next line instead of config.save() and works the same.
config.save(new PrintWriter(new File(dnsXmlPath)));