Flesh out the apispec some more and make the basic schemathesis runs pass

This is passing only with the local patch I made too work around this issue:
    https://github.com/schemathesis/schemathesis/issues/850
This commit is contained in:
R Tyler Croy 2020-11-08 14:09:35 -08:00
parent 25a2bf6fb6
commit 35ec2e63bb
4 changed files with 61 additions and 21 deletions

1
Cargo.lock generated
View File

@ -1511,6 +1511,7 @@ dependencies = [
"pest",
"pest_derive",
"pretty_env_logger 0.4.0",
"serde_json",
"serde_yaml",
"tide",
]

View File

@ -19,5 +19,6 @@ otto-models = { path = "../../models" }
pest = "~2.1.3"
pest_derive = "~2.1.0"
pretty_env_logger = "~0.4.0"
serde_json = "~1.0.59"
serde_yaml = "~0.8.13"
tide = "~0.14.0"

View File

@ -35,12 +35,19 @@ paths:
text/plain:
schema:
type: string
examples:
success:
summary: 'Simple Empty Pipeline'
value: |
pipeline {
stages {
stage {
name = 'Build'
steps {
sh 'ls'
}
}
}
}
responses:
@ -56,6 +63,9 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ParsePipelineFailure'
'422':
description: Unprocessable data, usually non-UTF-6 encoded
components:
schemas:
ParsePipelineResponse:
@ -71,6 +81,22 @@ components:
ParsePipelineFailure:
type: object
example: {}
properties: {}
example:
required:
- variant
- location
- line
- column
properties:
variant:
description: Variant of the parser error
type: string
location:
description: The location in the input stream where the error was detected.
type: string
line:
description: The line within the input stream where the error was detected.
type: number
column:
description: The column within the line of the error.
type: number

View File

@ -3,30 +3,42 @@
* readable (YAML) structures which other components in Otto can use.
*/
#[macro_use]
extern crate serde_json;
use log::*;
use otto_parser::*;
use tide::{Request, Response};
async fn parse(mut req: Request<()>) -> tide::Result {
let buffer = req.body_string().await?;
if let Ok(body) = req.body_string().await {
let parsed = parse_pipeline_string(&body);
let parsed = parse_pipeline_string(&buffer);
match parsed {
Err(e) => {
let resp = Response::builder(400)
.body("{}")
.content_type("application/json")
.build();
return Ok(resp);
},
Ok(pipeline) => {
let resp = Response::builder(200)
.body(r#"{"meta" : {}}"#)
.content_type("application/json")
.build();
return Ok(resp);
match parsed {
Err(e) => {
error!("Failed to parse: {:#?}", e);
return Ok(Response::builder(400)
.body(json!({
"variant" : "",
"location" : "",
"line" : 0,
"column" : 0
}))
.content_type("application/json")
.build()
);
},
Ok(pipeline) => {
return Ok(Response::builder(200)
.body(json!({"meta": {}}))
.content_type("application/json")
.build());
}
}
}
// Setting the content type manually since body_string? won't return one
Ok(Response::builder(422).content_type("application/json").build())
}