2017-07-19 1 views
1

Ich habe für ein paar Stunden versucht, um dies zu beheben, bekomme ich den Fehler: [Fatal] Fehler beim Erstellen Client-Modell: Gefunden Operationsobjekte mit doppelten OperationId 'recent_items'. OperationId muss unter allen in der API beschriebenen Operationen eindeutig sein.doppelte OPI erhalten, wenn versucht wird, Ruhe api

ich Visual Studio 2017 Azure SQL-Datenbank C#

ich keine doppelte operationid in den unten sehen kann verwende (ich kann auch nicht scheinen, um es für die hier ordentlich formatiert werden - sehr traurig)

{ 
    "swagger": "2.0", 
    "info": { 
     "version": "v1", 
     "title": "azure_items_API" 
    }, 
    "host": "azureitemsapi20170719125618.azurewebsites.net", 
    "schemes": ["http"], 
    "paths": { 
     "/api/recent_items": { 
      "get": { 
       "tags": ["recent_items"], 
       "operationId": "recent_items_GetAllrecent_items", 
       "consumes": [], 
       "produces": ["application/json", 
       "text/json", 
       "application/xml", 
       "text/xml"], 
       "responses": { 
        "200": { 
         "description": "OK", 
         "schema": { 
          "type": "array", 
          "items": { 
           "$ref": "#/definitions/recent_items" 
          } 
         } 
        } 
       }, 
       "deprecated": false 
      }, 
      "post": { 
       "tags": ["recent_items"], 
       "operationId": "recent_items_Postrecent_items", 
       "consumes": ["application/json", 
       "text/json", 
       "application/xml", 
       "text/xml", 
       "application/x-www-form-urlencoded"], 
       "produces": ["application/json", 
       "text/json", 
       "application/xml", 
       "text/xml"], 
       "parameters": [{ 
        "name": "recent_items", 
        "in": "body", 
        "required": true, 
        "schema": { 
         "$ref": "#/definitions/recent_items" 
        } 
       }], 
       "responses": { 
        "200": { 
         "description": "OK", 
         "schema": { 
          "$ref": "#/definitions/recent_items" 
         } 
        } 
       }, 
       "deprecated": false 
      } 
     }, 
     "/api/recent_items/{id}": { 
      "get": { 
       "tags": ["recent_items"], 
       "operationId": "recent_items_Getrecent_items", 
       "consumes": [], 
       "produces": ["application/json", 
       "text/json", 
       "application/xml", 
       "text/xml"], 
       "parameters": [{ 
        "name": "id", 
        "in": "path", 
        "required": true, 
        "type": "integer", 
        "format": "int32" 
       }], 
       "responses": { 
        "200": { 
         "description": "OK", 
         "schema": { 
          "$ref": "#/definitions/recent_items" 
         } 
        } 
       }, 
       "deprecated": false 
      }, 
      "put": { 
       "tags": ["recent_items"], 
       "operationId": "recent_items_Putrecent_items", 
       "consumes": ["application/json", 
       "text/json", 
       "application/xml", 
       "text/xml", 
       "application/x-www-form-urlencoded"], 
       "produces": [], 
       "parameters": [{ 
        "name": "id", 
        "in": "path", 
        "required": true, 
        "type": "integer", 
        "format": "int32" 
       }, 
       { 
        "name": "recent_items", 
        "in": "body", 
        "required": true, 
        "schema": { 
         "$ref": "#/definitions/recent_items" 
        } 
       }], 
       "responses": { 
        "204": { 
         "description": "No Content" 
        } 
       }, 
       "deprecated": false 
      }, 
      "delete": { 
       "tags": ["recent_items"], 
       "operationId": "recent_items_Deleterecent_items", 
       "consumes": [], 
       "produces": ["application/json", 
       "text/json", 
       "application/xml", 
       "text/xml"], 
       "parameters": [{ 
        "name": "id", 
        "in": "path", 
        "required": true, 
        "type": "integer", 
        "format": "int32" 
       }], 
       "responses": { 
        "200": { 
         "description": "OK", 
         "schema": { 
          "$ref": "#/definitions/recent_items" 
         } 
        } 
       }, 
       "deprecated": false 
      } 
     } 
    }, 
    "definitions": { 
     "recent_items": { 
      "type": "object", 
      "properties": { 
       "id": { 
        "format": "int32", 
        "type": "integer" 
       }, 
       "item_number": { 
        "type": "string" 
       }, 
       "stop_name": { 
        "type": "string" 
       }, 
       "stop_address1": { 
        "type": "string" 
       } 
      } 
     } 
    } 
} 

Es hatte eine doppelte bekommen, aber ich habe von ihnen zu einem getAll in der Steuerung geändert. Hier ist der Controller in voller Länge:

public class recent_itemsController : ApiController 
{ 
    private first_choice_itemsEntities db = new first_choice_itemsEntities(); 

    // GET: api/recent_items 
    public IQueryable<recent_items> GetAllrecent_items() 
    { 
     return db.recent_items; 
    } 

    // GET: api/recent_items/5 
    [ResponseType(typeof(recent_items))] 
    public IHttpActionResult Getrecent_items(int id) 
    { 
     recent_items recent_items = db.recent_items.Find(id); 
     if (recent_items == null) 
     { 
      return NotFound(); 
     } 

     return Ok(recent_items); 
    } 

    // PUT: api/recent_items/5 
    [ResponseType(typeof(void))] 
    public IHttpActionResult Putrecent_items(int id, recent_items recent_items) 
    { 
     if (!ModelState.IsValid) 
     { 
      return BadRequest(ModelState); 
     } 

     if (id != recent_items.id) 
     { 
      return BadRequest(); 
     } 

     db.Entry(recent_items).State = EntityState.Modified; 

     try 
     { 
      db.SaveChanges(); 
     } 
     catch (DbUpdateConcurrencyException) 
     { 
      if (!recent_itemsExists(id)) 
      { 
       return NotFound(); 
      } 
      else 
      { 
       throw; 
      } 
     } 

     return StatusCode(HttpStatusCode.NoContent); 
    } 

    // POST: api/recent_items 
    [ResponseType(typeof(recent_items))] 
    public IHttpActionResult Postrecent_items(recent_items recent_items) 
    { 
     if (!ModelState.IsValid) 
     { 
      return BadRequest(ModelState); 
     } 

     db.recent_items.Add(recent_items); 
     db.SaveChanges(); 

     return CreatedAtRoute("DefaultApi", new { id = recent_items.id }, recent_items); 
    } 

    // DELETE: api/recent_items/5 
    [ResponseType(typeof(recent_items))] 
    public IHttpActionResult Deleterecent_items(int id) 
    { 
     recent_items recent_items = db.recent_items.Find(id); 
     if (recent_items == null) 
     { 
      return NotFound(); 
     } 

     db.recent_items.Remove(recent_items); 
     db.SaveChanges(); 

     return Ok(recent_items); 
    } 

    protected override void Dispose(bool disposing) 
    { 
     if (disposing) 
     { 
      db.Dispose(); 
     } 
     base.Dispose(disposing); 
    } 

    private bool recent_itemsExists(int id) 
    { 
     return db.recent_items.Count(e => e.id == id) > 0; 
    } 
} 

Antwort

2

Ich musste schließlich gehen zurück und entfernen jeden Strich ‚_‘ in meinem Modell und Controller.

Ich entfernte sie in der Datenbank Tabellenname und Felder für ein gutes Maß ... Ich bin mir nicht sicher, ob das erforderlich war.

Das ist extrem frustrierend und eine Verschwendung von dem, was ein guter Nachmittag war.

Hoffe das hilft jemand anderem.

Verwandte Themen