Comments (5)
@s12v, sorry for looking so late into it.
I have two remarks.
First, we don't have a null validation because we model it with Option
al types. That is, anything which is not required is wrapped into an Option
and the user has to deal with that. That is exactly the reason why this https://github.com/zalando/api-first-hand/pull/78/files#diff-c62960d334c61f68da8bb96a34038420R34 looks so alien.
Second, I can't really reproduce the issue. This is a specification I'm using:
swagger: '2.0'
info:
version: 1.0
title: Swagger Example
description: bla
basePath: /example
schemes:
- http
consumes:
- application/json
produces:
- application/json
paths:
/token:
post:
parameters:
- name: query
in: body
required: true
schema:
"$ref": "#/definitions/Query"
responses:
200:
description: bla
schema:
$ref: "#/definitions/Query"
definitions:
Query:
type: object
required:
- language
properties:
language:
type: string
And these are tests:
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{}' 'http://localhost:9000/example/token'
JsResultException: JsResultException(errors:List((/language,List(ValidationError(List(error.path.missing),WrappedArray())))))
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d 'http://localhost:9000/example/token'
Bad Request: Invalid Json: No content to map due to end-of-input\n at [Source: akka.util.ByteIterator$ByteArrayIterator$$anon$1@7c955531; line: 1, column: 0]
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"language": null }' 'http://localhost:9000/example/token'
JsResultException: JsResultException(errors:List((/language,List(ValidationError(List(error.expected.jsstring),WrappedArray())))))
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"language": "brainfuck" }' 'http://localhost:9000/example/token'
{"language":"brainfuck"}
I guess the error messages do not respect Accept
header but for me it looks like the non-optionality is working. If it's not, I'd propose to investigate how to get it to work with the Option
type, not with the validation.
Does it make sense?
from api-first-hand.
@slavaschmidt, thanks for looking into it. Behavior has changed in 0.2.0. Before, such errors were ignored and language property was null
. Now it throws play.api.libs.json.JsResultException
, which is still not optimal. Would be better to have error 400 with a corresponding message, IMO.
For missing query parameters it returns "Missing parameter: test1" and error 400 - not the standard validation error, but I think it's ok.
Missing path parameter it's 404 - looks good.
Regarding Option
- I don't understand, required properties are not optionals. My PR handles only required properties.
I think I change the code to work only with Schema
, it will be shorter and tests will pass ;-)
WDYT?
from api-first-hand.
Hm, actually my fix not going to work anymore, because JsResultException
is thrown before validation (makes sense). Any idea how to handle it? Right now it's error 500 - internal server error. Should be 400 + message.
from api-first-hand.
Regarding Option - I don't understand, required properties are not optionals. My PR handles only required properties.
Exactly! Everything which is required is by definition not allowed to be null without additional validations. Everything not required is defined as an Option[T] with null values represented as None.
500 is bad, let us do something with that.
from api-first-hand.
Exactly! Everything which is required is by definition not allowed to be null without additional validations
I see. You're right. But it wasn't like this before! :) Looks like marshalling has been changed in 0.2.0
500 is bad, let us do something with that.
👍
from api-first-hand.
Related Issues (20)
- HTTP response headers HOT 1
- JSON schema enums produce code that does not compile. HOT 5
- Schema responses type should not have to start with capital letter HOT 3
- Easy question: Which of these exist vs. which of these are still in plans? HOT 2
- Run Your Application section ... ??? HOT 14
- What's Beta build-status: the plugin? HOT 5
- Type Naming of Basic Types HOT 1
- Is this doc still relevant? HOT 7
- Activator Template contents: checking/updating HOT 2
- User >: Any In SwaggerSecurityExtractors HOT 6
- Help with int64 & date-time HOT 5
- Extra nesting level for validation errors
- Create a testing environment for runtime issues
- Move from Activator to Giter8 HOT 2
- What is the Validation URL? HOT 1
- Use plugin without Activator HOT 2
- Add support for play 2.6
- is it possible to return a generic JSON? (no schema in swagger)
- Failure to parse a response with type: file
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from api-first-hand.