Go-swagger: Custom Validation

Created on 10 Apr 2017  路  3Comments  路  Source: go-swagger/go-swagger

Problem statement

Is it possible to write own validation for custom types ? If it is, can someone give me example ?

Environment

swagger version: 0.8.0

duplicate model question

Most helpful comment

For example.
There is bookstore, with info about books: author, title, price. And we want, that books from some author will not cost more the some price. So I want write function ValidateBookCustom() like

if book.author == "Some author" {
    if book.price > 1000 {
       return false
   }
    else return true
}

And I want to use this function.

All 3 comments

Can you elaborate a little bit more on this use case?

For example.
There is bookstore, with info about books: author, title, price. And we want, that books from some author will not cost more the some price. So I want write function ValidateBookCustom() like

if book.author == "Some author" {
    if book.price > 1000 {
       return false
   }
    else return true
}

And I want to use this function.

See also #1334

Was this page helpful?
0 / 5 - 0 ratings