|  | @@ -372,3 +372,217 @@ class TestDocGeneration(Base):
 | 
	
		
			
			| 372 | 372 |              'items': {'$ref': '#/definitions/{}'.format(schema_name)},
 | 
	
		
			
			| 373 | 373 |              'type': 'array'
 | 
	
		
			
			| 374 | 374 |          }
 | 
	
		
			
			|  | 375 | +
 | 
	
		
			
			|  | 376 | +    def test_func_schema_in_doc__ok__additionals_fields__query__string(self):
 | 
	
		
			
			|  | 377 | +        hapic = Hapic()
 | 
	
		
			
			|  | 378 | +        # TODO BS 20171113: Make this test non-bottle
 | 
	
		
			
			|  | 379 | +        app = bottle.Bottle()
 | 
	
		
			
			|  | 380 | +        hapic.set_context(MyContext(app=app))
 | 
	
		
			
			|  | 381 | +
 | 
	
		
			
			|  | 382 | +        class MySchema(marshmallow.Schema):
 | 
	
		
			
			|  | 383 | +            category = marshmallow.fields.String(
 | 
	
		
			
			|  | 384 | +                required=True,
 | 
	
		
			
			|  | 385 | +                description='a description',
 | 
	
		
			
			|  | 386 | +                example='00010',
 | 
	
		
			
			|  | 387 | +                format='binary',
 | 
	
		
			
			|  | 388 | +                enum=['01000', '11111'],
 | 
	
		
			
			|  | 389 | +                maxLength=5,
 | 
	
		
			
			|  | 390 | +                minLength=5,
 | 
	
		
			
			|  | 391 | +                # Theses none string specific parameters should disappear
 | 
	
		
			
			|  | 392 | +                # in query/path
 | 
	
		
			
			|  | 393 | +                maximum=400,
 | 
	
		
			
			|  | 394 | +                # exclusiveMaximun=False,
 | 
	
		
			
			|  | 395 | +                # minimum=0,
 | 
	
		
			
			|  | 396 | +                # exclusiveMinimum=True,
 | 
	
		
			
			|  | 397 | +                # multipleOf=1,
 | 
	
		
			
			|  | 398 | +            )
 | 
	
		
			
			|  | 399 | +
 | 
	
		
			
			|  | 400 | +        @hapic.with_api_doc()
 | 
	
		
			
			|  | 401 | +        @hapic.input_query(MySchema())
 | 
	
		
			
			|  | 402 | +        def my_controller():
 | 
	
		
			
			|  | 403 | +            return
 | 
	
		
			
			|  | 404 | +
 | 
	
		
			
			|  | 405 | +        app.route('/paper', method='POST', callback=my_controller)
 | 
	
		
			
			|  | 406 | +        doc = hapic.generate_doc()
 | 
	
		
			
			|  | 407 | +        assert doc.get('paths').get('/paper').get('post').get('parameters')[0]
 | 
	
		
			
			|  | 408 | +        field = doc.get('paths').get('/paper').get('post').get('parameters')[0]
 | 
	
		
			
			|  | 409 | +        assert field['description'] == 'a description\n\n*example value: 00010*'
 | 
	
		
			
			|  | 410 | +        # INFO - G.M - 01-06-2018 - Field example not allowed here,
 | 
	
		
			
			|  | 411 | +        # added in description instead
 | 
	
		
			
			|  | 412 | +        assert 'example' not in field
 | 
	
		
			
			|  | 413 | +        assert field['format'] == 'binary'
 | 
	
		
			
			|  | 414 | +        assert field['in'] == 'query'
 | 
	
		
			
			|  | 415 | +        assert field['type'] == 'string'
 | 
	
		
			
			|  | 416 | +        assert field['maxLength'] == 5
 | 
	
		
			
			|  | 417 | +        assert field['minLength'] == 5
 | 
	
		
			
			|  | 418 | +        assert field['required'] == True
 | 
	
		
			
			|  | 419 | +        assert field['enum'] == ['01000', '11111']
 | 
	
		
			
			|  | 420 | +        assert 'maximum' not in field
 | 
	
		
			
			|  | 421 | +
 | 
	
		
			
			|  | 422 | +    def test_func_schema_in_doc__ok__additionals_fields__path__string(self):
 | 
	
		
			
			|  | 423 | +        hapic = Hapic()
 | 
	
		
			
			|  | 424 | +        # TODO BS 20171113: Make this test non-bottle
 | 
	
		
			
			|  | 425 | +        app = bottle.Bottle()
 | 
	
		
			
			|  | 426 | +        hapic.set_context(MyContext(app=app))
 | 
	
		
			
			|  | 427 | +
 | 
	
		
			
			|  | 428 | +        class MySchema(marshmallow.Schema):
 | 
	
		
			
			|  | 429 | +            category = marshmallow.fields.String(
 | 
	
		
			
			|  | 430 | +                required=True,
 | 
	
		
			
			|  | 431 | +                description='a description',
 | 
	
		
			
			|  | 432 | +                example='00010',
 | 
	
		
			
			|  | 433 | +                format='binary',
 | 
	
		
			
			|  | 434 | +                enum=['01000', '11111'],
 | 
	
		
			
			|  | 435 | +                maxLength=5,
 | 
	
		
			
			|  | 436 | +                minLength=5,
 | 
	
		
			
			|  | 437 | +                # Theses none string specific parameters should disappear
 | 
	
		
			
			|  | 438 | +                # in query/path
 | 
	
		
			
			|  | 439 | +                maximum=400,
 | 
	
		
			
			|  | 440 | +                # exclusiveMaximun=False,
 | 
	
		
			
			|  | 441 | +                # minimum=0,
 | 
	
		
			
			|  | 442 | +                # exclusiveMinimum=True,
 | 
	
		
			
			|  | 443 | +                # multipleOf=1,
 | 
	
		
			
			|  | 444 | +            )
 | 
	
		
			
			|  | 445 | +
 | 
	
		
			
			|  | 446 | +        @hapic.with_api_doc()
 | 
	
		
			
			|  | 447 | +        @hapic.input_path(MySchema())
 | 
	
		
			
			|  | 448 | +        def my_controller():
 | 
	
		
			
			|  | 449 | +            return
 | 
	
		
			
			|  | 450 | +
 | 
	
		
			
			|  | 451 | +        app.route('/paper', method='POST', callback=my_controller)
 | 
	
		
			
			|  | 452 | +        doc = hapic.generate_doc()
 | 
	
		
			
			|  | 453 | +        assert doc.get('paths').get('/paper').get('post').get('parameters')[0]
 | 
	
		
			
			|  | 454 | +        field = doc.get('paths').get('/paper').get('post').get('parameters')[0]
 | 
	
		
			
			|  | 455 | +        assert field['description'] == 'a description\n\n*example value: 00010*'
 | 
	
		
			
			|  | 456 | +        # INFO - G.M - 01-06-2018 - Field example not allowed here,
 | 
	
		
			
			|  | 457 | +        # added in description instead
 | 
	
		
			
			|  | 458 | +        assert 'example' not in field
 | 
	
		
			
			|  | 459 | +        assert field['format'] == 'binary'
 | 
	
		
			
			|  | 460 | +        assert field['in'] == 'path'
 | 
	
		
			
			|  | 461 | +        assert field['type'] == 'string'
 | 
	
		
			
			|  | 462 | +        assert field['maxLength'] == 5
 | 
	
		
			
			|  | 463 | +        assert field['minLength'] == 5
 | 
	
		
			
			|  | 464 | +        assert field['required'] == True
 | 
	
		
			
			|  | 465 | +        assert field['enum'] == ['01000', '11111']
 | 
	
		
			
			|  | 466 | +        assert 'maximum' not in field
 | 
	
		
			
			|  | 467 | +
 | 
	
		
			
			|  | 468 | +    def test_func_schema_in_doc__ok__additionals_fields__path__number(self):
 | 
	
		
			
			|  | 469 | +        hapic = Hapic()
 | 
	
		
			
			|  | 470 | +        # TODO BS 20171113: Make this test non-bottle
 | 
	
		
			
			|  | 471 | +        app = bottle.Bottle()
 | 
	
		
			
			|  | 472 | +        hapic.set_context(MyContext(app=app))
 | 
	
		
			
			|  | 473 | +
 | 
	
		
			
			|  | 474 | +        class MySchema(marshmallow.Schema):
 | 
	
		
			
			|  | 475 | +            category = marshmallow.fields.Integer(
 | 
	
		
			
			|  | 476 | +                required=True,
 | 
	
		
			
			|  | 477 | +                description='a number',
 | 
	
		
			
			|  | 478 | +                example='12',
 | 
	
		
			
			|  | 479 | +                format='int64',
 | 
	
		
			
			|  | 480 | +                enum=[4, 6],
 | 
	
		
			
			|  | 481 | +                # Theses none string specific parameters should disappear
 | 
	
		
			
			|  | 482 | +                # in query/path
 | 
	
		
			
			|  | 483 | +                maximum=14,
 | 
	
		
			
			|  | 484 | +                exclusiveMaximun=False,
 | 
	
		
			
			|  | 485 | +                minimum=0,
 | 
	
		
			
			|  | 486 | +                exclusiveMinimum=True,
 | 
	
		
			
			|  | 487 | +                multipleOf=2,
 | 
	
		
			
			|  | 488 | +            )
 | 
	
		
			
			|  | 489 | +
 | 
	
		
			
			|  | 490 | +        @hapic.with_api_doc()
 | 
	
		
			
			|  | 491 | +        @hapic.input_path(MySchema())
 | 
	
		
			
			|  | 492 | +        def my_controller():
 | 
	
		
			
			|  | 493 | +            return
 | 
	
		
			
			|  | 494 | +
 | 
	
		
			
			|  | 495 | +        app.route('/paper', method='POST', callback=my_controller)
 | 
	
		
			
			|  | 496 | +        doc = hapic.generate_doc()
 | 
	
		
			
			|  | 497 | +        assert doc.get('paths').get('/paper').get('post').get('parameters')[0]
 | 
	
		
			
			|  | 498 | +        field = doc.get('paths').get('/paper').get('post').get('parameters')[0]
 | 
	
		
			
			|  | 499 | +        assert field['description'] == 'a number\n\n*example value: 12*'
 | 
	
		
			
			|  | 500 | +        # INFO - G.M - 01-06-2018 - Field example not allowed here,
 | 
	
		
			
			|  | 501 | +        # added in description instead
 | 
	
		
			
			|  | 502 | +        assert 'example' not in field
 | 
	
		
			
			|  | 503 | +        assert field['format'] == 'int64'
 | 
	
		
			
			|  | 504 | +        assert field['in'] == 'path'
 | 
	
		
			
			|  | 505 | +        assert field['type'] == 'integer'
 | 
	
		
			
			|  | 506 | +        assert field['maximum'] == 14
 | 
	
		
			
			|  | 507 | +        assert field['minimum'] == 0
 | 
	
		
			
			|  | 508 | +        assert field['exclusiveMinimum'] == True
 | 
	
		
			
			|  | 509 | +        assert field['required'] == True
 | 
	
		
			
			|  | 510 | +        assert field['enum'] == [4, 6]
 | 
	
		
			
			|  | 511 | +        assert field['multipleOf'] == 2
 | 
	
		
			
			|  | 512 | +
 | 
	
		
			
			|  | 513 | +    def test_func_schema_in_doc__ok__additionals_fields__body__number(self):
 | 
	
		
			
			|  | 514 | +        hapic = Hapic()
 | 
	
		
			
			|  | 515 | +        # TODO BS 20171113: Make this test non-bottle
 | 
	
		
			
			|  | 516 | +        app = bottle.Bottle()
 | 
	
		
			
			|  | 517 | +        hapic.set_context(MyContext(app=app))
 | 
	
		
			
			|  | 518 | +
 | 
	
		
			
			|  | 519 | +        class MySchema(marshmallow.Schema):
 | 
	
		
			
			|  | 520 | +            category = marshmallow.fields.Integer(
 | 
	
		
			
			|  | 521 | +                required=True,
 | 
	
		
			
			|  | 522 | +                description='a number',
 | 
	
		
			
			|  | 523 | +                example='12',
 | 
	
		
			
			|  | 524 | +                format='int64',
 | 
	
		
			
			|  | 525 | +                enum=[4, 6],
 | 
	
		
			
			|  | 526 | +                # Theses none string specific parameters should disappear
 | 
	
		
			
			|  | 527 | +                # in query/path
 | 
	
		
			
			|  | 528 | +                maximum=14,
 | 
	
		
			
			|  | 529 | +                exclusiveMaximun=False,
 | 
	
		
			
			|  | 530 | +                minimum=0,
 | 
	
		
			
			|  | 531 | +                exclusiveMinimum=True,
 | 
	
		
			
			|  | 532 | +                multipleOf=2,
 | 
	
		
			
			|  | 533 | +            )
 | 
	
		
			
			|  | 534 | +
 | 
	
		
			
			|  | 535 | +        @hapic.with_api_doc()
 | 
	
		
			
			|  | 536 | +        @hapic.input_body(MySchema())
 | 
	
		
			
			|  | 537 | +        def my_controller():
 | 
	
		
			
			|  | 538 | +            return
 | 
	
		
			
			|  | 539 | +
 | 
	
		
			
			|  | 540 | +        app.route('/paper', method='POST', callback=my_controller)
 | 
	
		
			
			|  | 541 | +        doc = hapic.generate_doc()
 | 
	
		
			
			|  | 542 | +
 | 
	
		
			
			|  | 543 | +        schema_field = doc.get('definitions', {}).get('MySchema', {}).get('properties', {}).get('category', {})  # nopep8
 | 
	
		
			
			|  | 544 | +        assert schema_field
 | 
	
		
			
			|  | 545 | +        assert schema_field['description'] == 'a number'
 | 
	
		
			
			|  | 546 | +        assert schema_field['example'] == '12'
 | 
	
		
			
			|  | 547 | +        assert schema_field['format'] == 'int64'
 | 
	
		
			
			|  | 548 | +        assert schema_field['type'] == 'integer'
 | 
	
		
			
			|  | 549 | +        assert schema_field['maximum'] == 14
 | 
	
		
			
			|  | 550 | +        assert schema_field['minimum'] == 0
 | 
	
		
			
			|  | 551 | +        assert schema_field['exclusiveMinimum'] == True
 | 
	
		
			
			|  | 552 | +        assert schema_field['enum'] == [4, 6]
 | 
	
		
			
			|  | 553 | +        assert schema_field['multipleOf'] == 2
 | 
	
		
			
			|  | 554 | +
 | 
	
		
			
			|  | 555 | +    def test_func_schema_in_doc__ok__additionals_fields__body__string(self):
 | 
	
		
			
			|  | 556 | +        hapic = Hapic()
 | 
	
		
			
			|  | 557 | +        # TODO BS 20171113: Make this test non-bottle
 | 
	
		
			
			|  | 558 | +        app = bottle.Bottle()
 | 
	
		
			
			|  | 559 | +        hapic.set_context(MyContext(app=app))
 | 
	
		
			
			|  | 560 | +
 | 
	
		
			
			|  | 561 | +        class MySchema(marshmallow.Schema):
 | 
	
		
			
			|  | 562 | +            category = marshmallow.fields.String(
 | 
	
		
			
			|  | 563 | +                required=True,
 | 
	
		
			
			|  | 564 | +                description='a description',
 | 
	
		
			
			|  | 565 | +                example='00010',
 | 
	
		
			
			|  | 566 | +                format='binary',
 | 
	
		
			
			|  | 567 | +                enum=['01000', '11111'],
 | 
	
		
			
			|  | 568 | +                maxLength=5,
 | 
	
		
			
			|  | 569 | +                minLength=5,
 | 
	
		
			
			|  | 570 | +            )
 | 
	
		
			
			|  | 571 | +
 | 
	
		
			
			|  | 572 | +        @hapic.with_api_doc()
 | 
	
		
			
			|  | 573 | +        @hapic.input_body(MySchema())
 | 
	
		
			
			|  | 574 | +        def my_controller():
 | 
	
		
			
			|  | 575 | +            return
 | 
	
		
			
			|  | 576 | +
 | 
	
		
			
			|  | 577 | +        app.route('/paper', method='POST', callback=my_controller)
 | 
	
		
			
			|  | 578 | +        doc = hapic.generate_doc()
 | 
	
		
			
			|  | 579 | +
 | 
	
		
			
			|  | 580 | +        schema_field = doc.get('definitions', {}).get('MySchema', {}).get('properties', {}).get('category', {})  # nopep8
 | 
	
		
			
			|  | 581 | +        assert schema_field
 | 
	
		
			
			|  | 582 | +        assert schema_field['description'] == 'a description'
 | 
	
		
			
			|  | 583 | +        assert schema_field['example'] == '00010'
 | 
	
		
			
			|  | 584 | +        assert schema_field['format'] == 'binary'
 | 
	
		
			
			|  | 585 | +        assert schema_field['type'] == 'string'
 | 
	
		
			
			|  | 586 | +        assert schema_field['maxLength'] == 5
 | 
	
		
			
			|  | 587 | +        assert schema_field['minLength'] == 5
 | 
	
		
			
			|  | 588 | +        assert schema_field['enum'] == ['01000', '11111']
 |