Skip to content

Commit

Permalink
feat: try to add openapi
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Mar 8, 2021
1 parent cf23058 commit 11fc8a6
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 3 deletions.
41 changes: 38 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 109 additions & 0 deletions _fixtures/swagger/petstore.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: listPets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: integer
format: int32
responses:
'200':
description: An paged array of pets
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
post:
summary: Create a pet
operationId: createPets
tags:
- pets
responses:
'201':
description: Null response
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
/pets/{petId}:
get:
summary: Info for a specific pet
operationId: showPetById
tags:
- pets
parameters:
- name: petId
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
responses:
'200':
description: Expected response to a valid request
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
schemas:
Pet:
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Pets:
type: array
items:
$ref: "#/components/schemas/Pet"
Error:
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
1 change: 1 addition & 0 deletions plugins/coco_swagger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
openapi = "0.1.5"

[dependencies.core_model]
path = "../../core_model"
Expand Down
39 changes: 39 additions & 0 deletions plugins/coco_swagger/src/coco_swagger_plugin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
extern crate openapi;

use std::path::Path;

pub fn analysis(path: &Path) {
match openapi::from_path(path) {
Ok(spec) => println!("spec: {:?}", spec),
Err(err) => println!("error: {}", err),
}
}

#[cfg(test)]
mod tests {
use crate::coco_swagger_plugin::analysis;
use std::path::PathBuf;

pub fn swagger_dir() -> PathBuf {
let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.unwrap()
.parent()
.unwrap()
.to_path_buf();
let ctags_dir = root_dir
.clone()
.join("_fixtures")
.join("swagger")
.join("petstore.yaml");

return ctags_dir;
}

#[test]
fn should_run_openapi_analysis() {
analysis(&*swagger_dir());
// println!("{:?}", spec);
// assert_eq!("", spec.host.unwrap());
}
}
2 changes: 2 additions & 0 deletions plugins/coco_swagger/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use core_model::CocoConfig;
use core_model::PluginInterface;

pub mod coco_swagger_plugin;

pub struct CocoSwagger {}

impl PluginInterface for CocoSwagger {
Expand Down

0 comments on commit 11fc8a6

Please sign in to comment.