How to import a component from another OpenAPI file? - swagger

Can you import a component that is defined in an other OpenAPI file?
Suppose I have two openAPI files:
openAPI.yaml and otherOpenAPI.yaml.
In openAPI.yml I want to use the myItem component that is defined in otherOpenAPI.yaml
Can I do something in the likes of:
$ref: './otherOpenAPI.yaml/components/myItem ?

You can use:
$ref: './otherOpenApi.yaml#/components/MyItem'

Related

Swagger exception when trying to resolve protcol buffer generated Java classes

I am trying to generate a json rest api. My return Object to the client are classes generated from protocol buffers. So I tweacked jackson to convert the protobuf messages into json,so the rest api works. But when adding swagger, I get an exception when trying to create the swagger definition file.
Here is how I try to create the definition file:
SwaggerConfiguration oasConfig = new SwaggerConfiguration().openAPI(oas);
Reader reader = new Reader(oasConfig);
OpenAPI openAPI = reader.read(app.getClasses());
swagger = Json.pretty(openAPI);
The Exception I am getting is
java.lang.IllegalArgumentException: Conflicting setter definitions for property "author": bisq.social.protobuf.PrivateTradeChatMessage$Builder#setAuthor(bisq.social.protobuf.ChatUser) vs bisq.social.protobuf.PrivateTradeChatMessage$Builder#setAuthor(bisq.social.protobuf.ChatUser$Builder)
at com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder._selectSetterFromMultiple(POJOPropertyBuilder.java:561)
Since the Java classes being analyzed here are generated, I am not able to change them.
Is there a way to make swagger work with protobuf generated classes?
This is using swagger 2.2.0 and jackson 2.13.2

Swagger definition: $ref and required

so, I want to write a definition like this:
components:
accuracy::
$ref: '#/definitions/accuracy'
required: false
and 'override' a required property. But the documentation says:
Any sibling elements of a $ref are ignored. This is because $ref works
by replacing itself and everything on its level with the definition it
is pointing at.
So, is there any way to achieve this behavior?
required is not a property attribute, it's an object attribute containing a list of required properties. So you should use:
MyObject:
type: object
properties:
accuracy:
$ref: '#/definitions/accuracy'
required:
- accuracy

Is there an equivalent of C#'s using T = X.Y.Z import directive in F#?

In C# I can define an alias for a type by writing
using Foo = Full.Name.Space.Of.My.TypeWithAVeryLongName;
Within the code file I can from then on refer to my type via Foo instead of TypeWithAVeryLongName and there is no need to import Full.Name.Space.Of.My.
How do I have to change the open ... directive in F# to achieve something similar?
You can declare a type abbrevation:
type Foo = Full.Name.Space.Of.My.TypeWithAVeryLongName
Just some additinal info, if you just want an abbreviation for your type Taylor Wood's answer is the one.
If you want to abbreviate (or change) a module name, you can use:
module Short = MyVeryLong.Helpers.Container
where the namespace is defined as
module MyVeryLong.Helpers.Container in another place/file/dll. And you can refer to your type as Short.MyType.
but this will only work for a module nested in a namespace. To my knowledge you cannot abbreviate pure namespace names.

xtext: autoimport and -validate current package

I have two connected problems that I kind of know how to solve "by foot" (using custom validators and scope providers). But I'm surprised they don't work out of the box in xtext so I'll ask anyway (in case I missed something).
I have this DSL:
Model:
'package' name=QualifiedName
imports+=Import*
entities+=Entity*;
Import:
'import' importedNamespace=QualifiedName;
Entity:
name=ID '{'
references += Reference*
'}';
Reference:
name=ID':'entitiy=[Entity]
;
QualifiedName:
ID('.'ID)*
;
Apart from defining multiple entities in the same file I want to be able to define multiple files that "live" in the same package. And I have 2 problems here:
1) I found no obvious way to easily auto-import all elements from the current package. So If I have one file
package com.test
EntityA {}
and a second one
package com.test
import com.test.EntityA // fails if I remove this line
EntityB{
refToA:EntityA // I could make qualified names work here.
// But that is not the goal.
}
the reference to EntityA can't be resolved unless I explicitly import it (which is something that I want to avoid) although they are in the same namespace.
So: is there a way to easily enable outimports for the "current" package?
2) I have enabled the org.eclipse.xtext.validation.NamesAreUniqueValidator which works fine for entities defined in the same file. But if I redefine an imported entity like this
package com.test
import com.test.EntityA
EntityB{
refToA:EntityA
}
EntityA {}
I don't get the expected validation error. Is there something I can do about that without having to write my own validator?
Thx.
To make auto-imports work, you need to use Xbase and
Model:
'package' name=QualifiedName
importSection=XImportSection?
To use Xbase, append this to your grammar: with org.eclipse.xtext.xbase.Xbase
See http://www.lorenzobettini.it/2013/01/the_ximportsection_in_xbase_2_4/ for details.
The second one can only be solved with your own validator AFAIK. The reason is that you can have a grammar which allows:
import com.test.EntityA as X
private EntityA extends X {}

Xtext Import with ScopeProvider

I have a grammar within Xtext that has a custom ScopeProvider, which extends AbstractDeclarativeScopeProvider. I am using this scope provider to accurately scope elements within the same DSL file.
It is simple to scope within the file, as one can simply traverse upwards/downwards through the model.
However, I'd now like to support imports from other classes. But I'm stuck how to find the elements in the other files from within my scope provider.
I can find instances of the import, which are specified in the grammar as:
Import:
"import" importURI=STRING
;
I can obtain the references to the import from the model, but this just contains the strings that are the URIs that reference the other files.
How to I get to the elements within the imported file?
hi i am not quite sure what your usecase is. the import statements simply makes the elements from the imported resources visible so that you can reference them
Model:
imports+=Import*
defines+=Define*
uses+=Use*
;
Import:
"import" importURI=STRING
;
Define:
"def" name=ID
;
Use:
"use" use=[Define]
;
with
a.mydsl
def a
b.mydsl
import "a.mydsl"
use a
i dont know why you explicitly want to search find it in the scopeprovider.
they are visible automatically
you may call
delegeteGetScope(ctx,ref)
in the scopeprovider to access the outer scope (the one from the imported files)
but what todo with it highly depends on your usecase

Resources