Generate swagger 2.0 yaml using swagger 4.x package - swagger

I am going to integrate my API server to Google Cloud Endpoints.
And Google Cloud Endpoints supports swagger 2.0 as of now.
But my dependencies/libraries are up versions now. So I want to generate swagger 2.0 yaml file without downgrading swagger library version (api end points are already described with swagger 4.x - openapi 3.0 spec).
Nestjs and swagger dependencies (package.json):
...
"#nestjs/common": "^7.0.0",
"#nestjs/config": "^0.4.0",
"#nestjs/core": "^7.0.0",
"#nestjs/platform-express": "^7.0.0",
"js-yaml": "^3.14.0",
...
"#nestjs/swagger": "^4.5.4",
"swagger-ui-express": "^4.1.4",
...
And swagger generator script:
import { NestFactory } from '#nestjs/core';
import { AppModule } from './app.module';
import * as fs from 'fs'
import * as yaml from 'js-yaml'
const generateSwaggerYaml = async () => {
const app = await NestFactory.create(AppModule);
const options = new DocumentBuilder()
.setTitle('API Title')
.setDescription('API Description')
.build()
const document = SwaggerModule.createDocument(app, options)
fs.writeFileSync("./openapi-run.yaml", yaml.safeDump(document))
}
generateSwaggerYaml()
And output of script is openapi 3.0 spec :(
openapi: 3.0.0
info:
title: API Title
description: API Description.
version: 1.0.0
contact: {}
tags: []
servers: []
...
Is there any option/way to generate swagger2.0 yaml from openapi 3.0 document?
How can I downgrade openapi 3.0 spec to swagger 2.0 spec?

I use this project from github for that very purpose: https://github.com/LucyBot-Inc/api-spec-converter
For openapi 3 yaml to swagger 2 yaml, it's as simple as $ api-spec-converter --from openapi_3 --syntax yaml --to swagger_2 ${f} > ${SWAGGER_V2_FILE}

Related

AWS CDK Create API Gateway using OpenAPI Spec with Private Endpoint

I am trying to work out the correct way to attach a VPC Endpoint to an API gateway using an OpenAPI Spec.
Here is what I have so far:
CDK:
var apiDefinition = ApiDefinition.FromAsset("./openapi_replaced.yaml");
var api = new SpecRestApi(this, "api", new SpecRestApiProps {
ApiDefinition= apiDefinition,
});
OpenAPI Spec:
servers:
- url: ""
x-amazon-apigateway-endpoint-configuration:
vpcEndpointIds:
- vpce-1111aaaa00001111
Will this attach the VPC Endpoint to my API Gateway as a Private Endpoint?

SwaggerUI Docker support for two api files (locally)

I'm trying to create a Swagger UI configuration to show several of my apis. They are not hosted publicly, the definition files are in my local file system. I'm using swagger ui with docker. I run it with the following command:
docker run -p 8080:8080 -v $(pwd)/_build:/spec swaggerapi/swagger-ui
In _build directory is where I have my yaml spec files. This is the swagger-config.yaml config file:
urls:
- /spec/openapi2.yaml
- /spec/openapi.yaml
plugins:
- topbar
I have also tried:
urls:
- url: /spec/openapi2.yaml
name: API1
- url: /spec/openapi.yaml
name: API2
plugins:
- topbar
After running it, this is what I see:
That's the default API of Swagger UI, so I suppose there's an error in my configuration. I have tried several things, but they have not worked and I do not seem to find any good documentation about the swagger-config.yaml configuration file.
Any idea to make it work with several APIs?
According to the comments in the Swagger UI issue tracker, the Docker version needs the config file in the JSON format rather than YAML.
Try using this swagger-config.json:
{
"urls": [
{
"url": "/spec/openapi2.yaml",
"name": "API1"
},
{
"url": "/spec/openapi.yaml",
"name": "API2"
}
],
"plugins": [
"topbar"
]
}
Also add -e CONFIG_URL=/path/to/swagger-config.json to the docker run command.

Apollo client with Vue and rails

I have a rails app which is actually a clone of yts.mx. Now the idea was to have the front-end work in Vue.js, for which I created an independent Vue project inside the root directory of the existing rails app.
I have written GraphQl queries and tried using apollo client for communication with Vue but it gives me a dependency not found error with the path of the module Iv'e imported.
This dependency was not found:
* graphql/queries/movies/retrieveMovies.gql in ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/MovieBlock.vue?vue&type=script&lang=js&
To install it, you can run: npm install --save graphql/queries/movies/retrieveMovies.gql
Here's my retrieveMovies.gql file
query {
movies{
name
release_date
}
}
here's the script tag for the MovieBlock.vue Vue component
<script>
import GET_MOVIES from 'graphql/queries/movies/retrieveMovies.gql'
export default {
name: 'MovieBlock',
apollo: {
movies: {
query: GET_MOVIES,
update: data => {
debugger
}
}
},
data () {
return {
movies: []
}
}
}
</script>
Here's the Directory Structure of the project:

Problem building a Vue.js 3 (beta) app, with Rollup: "Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)"

I'm trying to build a Vue.js 3 (beta) application, using Rollup.
Vue.js 3.0.0-beta.15
Rollup 2.18.1
rollup-plugin-vue 6.0.0-beta.6
I get this:
$ npx rollup -c rollup.config.prod.js
src/main.js → public/dist/...
[!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
src/App.vue?vue&type=style&index=0&id=7ba5bd90&scoped=true&lang.css (2:0)
Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
at error (/Users/asko/Git/GroundLevel-es6-firebase-web/node_modules/rollup/dist/shared/rollup.js:5154:30)
at Module.error (/Users/asko/Git/GroundLevel-es6-firebase-web/node_modules/rollup/dist/shared/rollup.js:9592:16)
at tryParse (/Users/asko/Git/GroundLevel-es6-firebase-web/node_modules/rollup/dist/shared/rollup.js:9506:23)
at Module.setSource (/Users/asko/Git/GroundLevel-es6-firebase-web/node_modules/rollup/dist/shared/rollup.js:9890:30)
at ModuleLoader.addModuleSource (/Users/asko/Git/GroundLevel-es6-firebase-web/node_modules/rollup/dist/shared/rollup.js:17749:20)
at ModuleLoader.fetchModule (/Users/asko/Git/GroundLevel-es6-firebase-web/node_modules/rollup/dist/shared/rollup.js:17803:9)
at async Promise.all (index 2)
at ModuleLoader.fetchStaticDependencies (/Users/asko/Git/GroundLevel-es6-firebase-web/node_modules/rollup/dist/shared/rollup.js:17827:34)
at async Promise.all (index 0)
at ModuleLoader.fetchModule (/Users/asko/Git/GroundLevel-es6-firebase-web/node_modules/rollup/dist/shared/rollup.js:17804:9)
at async Promise.all (index 3)
at ModuleLoader.fetchStaticDependencies (/Users/asko/Git/GroundLevel-es6-firebase-web/node_modules/rollup/dist/shared/rollup.js:17827:34)
at async Promise.all (index 0)
at ModuleLoader.fetchModule (/Users/asko/Git/GroundLevel-es6-firebase-web/node_modules/rollup/dist/shared/rollup.js:17804:9)
at async Promise.all (index 0)
My Rollup config:
import resolve from '#rollup/plugin-node-resolve';
import replace from '#rollup/plugin-replace';
import fileSize from 'rollup-plugin-filesize';
import vue from 'rollup-plugin-vue';
const plugins = [
resolve(),
vue({
template: {
isProduction: true,
//compilerOptions: { preserveWhitespace: false }
},
//css: false, // note: 'false' extracts styles as a separate '.css' file
}),
replace({ 'process.env.NODE_ENV': '"production"' }),
fileSize()
];
export default {
plugins,
input: 'src/main.js',
output: {
dir: 'public/dist/',
format: 'esm',
globals: {
firebaseui: "firebaseui"
},
sourcemap: true // have source map even for production
}
};
Have searched hard for similar cases, but not found a solution, yet. Does anyone know, what this might be about?
Sources: Sources: https://github.com/akauppi/GroundLevel-es6-firebase-web/tree/pr-prod

How can i configure oauth2 resourceserver for spring webflux app?

Spring security 5.1.0.Rc1 has come up with support for OAuth2 Resource Servers in webflux - https://spring.io/blog/2018/08/21/spring-security-5-1-0-rc1-released .
The example given here talks about Oauth2 based on JWT format .
how can i configure a oauth2 resource server based and specify the token decoding uri .
In spring MVC i could use #EnableResourceServer and security.oauth2.resource.token-info-uri property . How would i do the same with webflux ?
I don't know if it actually worked with RC1 but with 2.1.0.M1 I could get it to work like this:
build.gradle:
repositories {
mavenCentral()
maven {
url 'https://repo.spring.io/libs-snapshot'
}
}
dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-gateway:2.1.0.M1'
}
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-security'
compile 'org.springframework.security:spring-security-oauth2-jose'
compile 'org.springframework.security:spring-security-oauth2-client'
compile 'org.springframework.security:spring-security-oauth2-resource-server'
}
application.yaml
spring:
security:
oauth2:
resourceserver:
jwt:
jwk-set-uri: http://keycloak.example.com/auth/realms/your-realm/protocol/openid-connect/certs
Also there's a sample at https://github.com/spring-projects/spring-security/tree/master/samples/boot/oauth2resourceserver-webflux

Resources