I am very new to yaml file reading and writing , In most of the sites Deserialization and serialization is used for reading and writing and we need to define an object If we want to serialize & deserialize. but I have below file to add a yaml node but the structure not fixed So please help me to add a node in c# with in an yaml file.
I/p File
mescue_path: &mescue_path test/profile
fescue_path: &fescue_path details/prod
mescue_path_server: &mescue_path_server
role: auto
prefix: *mescue_path
fescue_path_server: &fescue_path_server
role: auto
prefix: *fescue_path
westRr: &westRr
<<: *mescue_path_server
rack: westRr
eastRr: &eastRr
<<: *mescue_path_server
rack: estRr
Mapping:
mechinerack1: *eastRack
mechinerack2: *eastRack
mechinerack3: *eastRack
mechinerack4: *eastRack
RRRack1: *westRack
RRRack2: *WestRack
O/P File:
mescue_path: &mescue_path test/profile
fescue_path: &fescue_path details/prod
mescue_path_server: &mescue_path_server
role: auto
prefix: *mescue_path
fescue_path_server: &fescue_path_server
role: auto
prefix: *fescue_path
westRr: &westRr
<<: *mescue_path_server
rack: westRr
*NorthRr: &NorthRr
<<: *mescue_path_server
rack: NorthRr*
eastRr: &eastRr
<<: *fescue_path_server
rack: estRr
Mapping:
mechinerack1: *eastRack
mechinerack2: *eastRack
mechinerack3: *eastRack
mechinerack4: *eastRack
RRRack1: *westRack
RRRack2: *WestRack
Related
I'm using the Swashbuckle.AspNetCore.Filters.SwaggerResponseExampleAttribute attribute to generate Swagger documentation that includes a single response example for a given HTTP status code, for a (.NET 6) ASP.NET Web API controller method, like so:
[SwaggerOperation(summary: "Delete all items in a cart.", description: "<p>BLAH BLAH BLAH.</p>")]
[SwaggerResponse(statusCode: 200, description: "<p>The API request was successfully processed; an object describing the empty shopping cart is returned.</p>", type: typeof(GetCartSummaryResponse)), SwaggerResponseExample(statusCode: 200, examplesProviderType: typeof(CartApi_DeleteAllItemsInCart_Http200ResponseExampleProvider))]
[SwaggerResponse(statusCode: 422, description: "The API request was unsuccessfully processed; one or more business requirements failed to be met as the request was processed.", type: typeof(ProblemDetails))]
[SwaggerResponseExample(statusCode: 422, examplesProviderType: typeof(CartApi_DeleteAllItemsInCart_Http422ResponseExampleProvider))]
[HttpPost("/cart/clear")]
[Consumes("application/json")]
[Produces("application/json")]
public ActionResult<GetCartSummaryResponse> DeleteAllItemsInCart()
{
throw new NotImplementedException();
}
Now I'd like to provide multiple examples of HTTP 422 response bodies that might be returned in the API response body, under specific conditions.
I'd planned on using my endpoint's examples: section in the OpenAPI 3.x document to accomplish this, like so:
paths:
'/cart/clear':
post:
tags:
- CartApi
summary: Delete all items in a cart.
description: <p><i>BLAH BLAH BLAH.</i></p>
operationId: CartApi_DeleteAllItemsInCart
responses:
'200':
description: <p>The API request was successfully processed; an object describing the empty shopping cart is returned.</p>
content:
application/json:
schema:
$ref: '#/components/schemas/GetCartSummaryResponse'
example:
cartGuid: 0fa1ef5f-5395-4679-901d-fd6c941f3460
cartItems: []
'422':
description: The API request was unsuccessfully processed; some other problem happened.
content:
application/json:
schema:
$ref: '#/components/schemas/ProblemDetails'
examples:
Shopping cart ID is null or whitespace:
value:
type: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/422'
title: Shopping cart was not found.
status: 422
detail: Shopping cart ID is null, empty, blank, or whitespace.
Shopping cart ID not found:
value:
type: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/422'
title: Shopping cart was not found.
status: 422
detail: Shopping cart ID was not found.
cartGuid: 0fa1ef5f-5395-4679-901d-fd6c941f3460
I've fairly certain the OpenAPI 3.x spec supports this feature -- see the "Multiple examples in response bodies:" section on the "Adding Examples" page. However, I can't figure out if Swashbuckle supports rendering the examples: section in an OpenAPI 3.x document yet. And if it does already support it, I've had no luck figuring out what attributes to use / what the code to do this looks like.
Any help would be greatly appreciated -- thanks in advance!
#CodingMytra commented on my OP & pointed me at an article that mentions how to use the Swashbuckle.AspNetCore.Filters package's IMultipleExamplesProvider<T> interface to generate the OpenAPI examples: section for a given API endpoint & HTTP response code.
For the sake of completeness, here's my class that implements IMultipleExamplesProvider<T>:
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Filters;
namespace api.Models.Responses.Examples._4xx;
public class CartApi_DeleteAllItemsInCart_Http422ResponseExamplesProvider : IMultipleExamplesProvider<ProblemDetails>
{
public IEnumerable<SwaggerExample<ProblemDetails>> GetExamples()
{
yield return SwaggerExample.Create(
name: "Shopping cart ID is invalid.",
value: new ProblemDetails {
Type = $#"https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/422",
Status = 422,
Title = "Shopping cart ID is invalid.",
Detail = "Shopping cart ID is null, empty, or whitespace, & cannot be used to access a shopping cart.",
Extensions = {{ "cartGuid", "BLAH_BLAH_BLAH" }}
}
);
yield return SwaggerExample.Create(
name: "Unable to access shopping cart.",
value: new ProblemDetails {
Type = $#"https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/422",
Status = 422,
Title = "Unable to access shopping cart.",
Detail = "Shopping cart ID is valid, but could not be used to access the shopping cart."
}
);
}
}
After that, I used the new pluralized CartApi_DeleteAllItemsInCart_Http422ResponseExamplesProvider class in my [SwaggerResponseExample] attribute & it generated the OpenAPI 3.x examples: section the way I'd expected:
'422':
description: The API request was unsuccessfully processed; shopping cart ID was not found.
content:
application/json:
schema:
$ref: '#/components/schemas/ProblemDetails'
examples:
Shopping cart ID is invalid.:
value:
type: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/422'
title: Shopping cart ID is invalid.
status: 422
detail: 'Shopping cart ID is null, empty, or whitespace, & cannot be used to access a shopping cart.'
cartGuid: 0fa1ef5f-5395-4679-901d-fd6c941f3460
Unable to access shopping cart.:
value:
type: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/422'
title: Unable to access shopping cart.
status: 422
detail: 'Shopping cart ID is valid, but could not be used to access the shopping cart.'
I need a sample powershell script to read values/single value from a given RESTFul API. Here is the URL of sample restful URL
http://dummy.restapiexample.com/
Below is the one I tried.But instead of count I wanted to get some employees data.
<!-- begin snippet: js hide: false console: true babel: false -->
$response = Invoke-RestMethod 'http://dummy.restapiexample.com/api/v1/employees'
$employees = $response.items.Count;
Write-Host "employees=$employees";
Output:
employees= 272
$response = Invoke-RestMethod 'http://dummy.restapiexample.com/api/v1/employees'
foreach($item in $response){
Write-Host "$item"
}
this will display each record..
Invoke-RestMethod 'http://dummy.restapiexample.com/api/v1/employees'
foreach($item in $response){
Write-Host $item.employee_name
}
this will display only names.
I have started playing around with react.js as a frontend web app and C# Web API and now I want to figure out how to set up the routes.
The current behavior:
When I run the server the application loads correctly with url:
localhost:port/page1
I can switch between pages in navigation bar easily. The url in browser is switching between localhost:port/page1,
localhost:port/page2 and localhost:port/page3
However if I enter for example localhost:port/page3 directly I will get No HTTP resource was found that matches the request URI localhost:port/page3
Can you please explain why using nav bar in react I can get the url correctly but when I enter it directly it will fail?
RouteConfig.cs (C# WebApi)
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "*",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
routes.js (react app)
where domu is page1, pacienti is page2 and tagy is page3
import React from 'react'
import { Route, IndexRoute, Redirect, IndexRedirect, hashHistory } from 'react-router'
import Layout from './components/utils/layout';
import Domu from './pages/domu';
import Pacienti from './pages/pacienti';
import Tagy from './pages/tagy';
const routes = (
<Router history={hashHistory}>
<Route history={hashHistory} path="/" component={Layout}>
<IndexRoute component={Domu}/>
<IndexRedirect to="domu" />
<Route path="domu" component={Domu}/>
<Route path="pacienti" component={Pacienti}/>
<Redirect from="*" to="pacienti" />
<Route path="tagy" component={Tagy}/>
</Route>
</Router>
);
export default routes;
header.js
import React from 'react';
import { Navbar, Nav, NavItem } from 'react-bootstrap';
import { LinkContainer } from 'react-router-bootstrap';
export default class Header extends React.Component {
render() {
return (
<Navbar inverse>
<Navbar.Header>
<Navbar.Brand>
<span style={{paddingLeft: '1em'}}>FNO - Urgent</span>
</Navbar.Brand>
<Nav>
<LinkContainer to="/Domu">
<NavItem eventKey={1} href="#/domu">Domu</NavItem>
</LinkContainer>
<LinkContainer to="/Pacienti">
<NavItem eventKey={2} href="#/pacienti">Pacienti</NavItem>
</LinkContainer>
<LinkContainer to="/Tagy">
<NavItem eventKey={2} href="#/tagy">Tagy</NavItem>
</LinkContainer>
</Nav>
</Navbar.Header>
<Nav pullRight>
<NavItem eventKey={1} href="#">Logout</NavItem>
</Nav>
</Navbar>
);
}
}
EDIT:
source codes available here: https://github.com/trannann/reactUrgent
I am using VS 2015 RC, working on a WebAPI project and when I try to use the routing in Angular 2 I get the following errors:
Failed to load resource: the server responded with a status of 404 (Not Found) localhost:14580/angular2/router
Potentially unhandled rejection [3] Error loading "angular2/router" at localhost:14580/angular2/router
Error loading "angular2/router" from "Components/main/main" at localhost:14580/Components/main/main.js
Not Found: localhost:14580/angular2/router (WARNING: non-Error used)
The view is the basic import of the main.ts component. The component code is as follows:
/// <reference path="../../Scripts/typings/angular2/angular2.d.ts" />
/// <reference path="../../Scripts/typings/_custom/ng2.d.ts" />
import {Router, RouteConfig, RouterLink, RouterOutlet} from 'angular2/router';
import {Component, View, bootstrap} from 'angular2/angular2';
import {Login} from '../login/login';
import {status, json} from 'Scripts/utils/fetch'
// Annotation section
#Component({
selector: 'my-app'
})
#View({
templateUrl: 'Views/main/main.html',
directives: [RouterLink, RouterOutlet]
})
#RouteConfig([
{ path: '/login', as: 'login', component: Login }
])
// Component controller
export class Main {
//router: Router;
name: string;
constructor(router: Router) {
//this.router = router;
this.name = 'Routing';
router.config([{ path: '/login', as: 'login', component: Login }]);
}
login(event, email, password) {
event.preventDefault();
window.fetch('/api/Account/Login', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
email, password
})
})
.then(status)
.then(json)
.then((response) => {
alert(response);
// this.router.parent.navigate('/home');
})
.catch((error) => {
alert(error.message);
console.log(error.message);
});
}
}
bootstrap(
Main
);
You need to include router.dev.js on your html in the same way you included angular2.dev.js. So simply add this line to your index.html's head:
<script src="../node_modules/angular2/bundles/router.dev.js"></script>
PS. I know you already solved this, but the answer was not clear and I took a while to realize what was wrong with my app.
If you bring in the latest definitelyTyped typings for Angular 2 it may be easier to get it working.
Here is a working example:
http://www.syntaxsuccess.com/viewarticle/routing-in-angular-2.0
The Http method used is GET and I'm calling the same webservice method (with same parameters).
But if I add to request an Accept header with application/json, the output differs.
The cause is a Bitmap field in my object named User, which holds an avatar image.
If i leave out the Accept application/json header, this is the simplified output (XML):
<!-- language: lang-xml -->
<ArrayOfUser xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/XTraN4ForcesFSDomain.Domain">
<User>
<Id>02ddf1e4-ad76-4778-8887-a186014939f8</Id>
<Avatar xmlns:d3p1="http://schemas.datacontract.org/2004/07/System.Drawing" i:nil="true" />
<IsActive>false</IsActive>
<LastAccess>0001-01-01T00:00:00</LastAccess>
<Username>quisquam</Username>
<!-- Other properties -->
</User>
<User>
<Id>17db833c-5008-44f0-a713-a186014c22a5</Id>
<Avatar xmlns:d3p1="http://schemas.datacontract.org/2004/07/System.Drawing">
<Data xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:base64Binary" xmlns="">iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAABGdBTUEAAK/INwWK6[...]BIJS/Wd6Pgu/mOoS/HADwfwFUI4VkJHOgAgAAAABJRU5ErkJggg==</Data>
</Avatar>
<IsActive>false</IsActive>
<LastAccess>0001-01-01T00:00:00</LastAccess>
<Username>labore</Username>
</User>
</ArrayOfUser>
Well, this is just fine! The image (Base64) is there. If I change my request to get JSON, it returns no image, just the name of the class that it represents:
<!-- language: lang-json -->
[
{
"Username": "quisquam",
"LastAccess": "0001-01-01T00:00:00",
"IsActive": false,
"Avatar": null,
"Id": "02ddf1e4-ad76-4778-8887-a186014939f8"
},
{
"Username": "reiciendis",
"LastAccess": "0001-01-01T00:00:00",
"IsActive": false,
"Avatar": "System.Drawing.Bitmap",
"Id": "17db833c-5008-44f0-a713-a186014c22a5"
},
]
The webservice mthod is
<!-- language: lang-c# -->
public IQueryable<User> Get()
{
// return stuff (no big deal here)
}
The code is the same, so why won't JSON return a base64 string like it should?
As LukeH said, converting my Bitmap to byte array solved my issues.